Difference between revisions of "GetInventoryObject"

From the Fallout3 GECK Wiki
Jump to navigation Jump to search
imported>WarMachineDD7
(Created page with "{{Function |origin = FOSE1 |summary = Returns the base form of the nth form in a container. |name = GetInventoryObject |alias = GetNthObject |returnType = ref |reference...")
 
imported>Odessa
m
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Function
{{Function
  |origin = FOSE1
  |origin = FOSE1
  |summary = Returns the base form of the nth form in a container.
  |summary = Returns the base form of the Nth item in a container.
  |name = GetInventoryObject
  |name = GetInventoryObject
  |alias = GetNthObject
  |alias = GetNthObject
  |returnType = ref
  |returnType = baseform
  |referenceType = ContainerRefID
  |referenceType = Container
  |arguments =  
  |arguments =  
   {{FunctionArgument
   {{FunctionArgument
   |Name = index
   |Name = index
   |Type = int
   |Type = int
   }}
   }}}}
|example = ref itemType
==Example==
int ammountOfItems
<pre>
ref rItem
set itemType to player.GetInventoryObject 5
 
set ammountOfItems to player.GetItemCount itemType
set rItem to PlayerREF.GetInventoryObject 21
This script will get the type of the 5th form in the player's inventory and then get the quantity of them.
</pre>
}}
Often you may wish to use this in a loop, to go through every item in an inventory:
<pre>
int x
ref rItem
 
let x := PlayerREF.GetNumItems
 
while x > 0
    let x -= 1 ; decrement x, the first item is '0'
    let rItem := PlayerREF.GetInventoryObject x
    ; do something
loop
</pre>
==Notes==
==Notes==
*The container's index starts at 1.
*Beware removing items from a container within a loop, because it may change the index of those later.
*Multiple instances of the same base form in a container are considered as just one item by the function.
*Multiple instances of the same base form in a container are considered as just one item by the function.
[[Category:Functions_(FOSE)]] [[Category:List_Functions]]
==See Also==
*[[ForEach]]
*[[GetNumItems]]
*[[GetEquippedObject]]
*[[GetRefs]]
*[[while]], [[let]]
*[[ShowInventory]] / [[Con_Inv]]
[[Category:Functions_(FOSE)]]

Latest revision as of 10:54, 14 September 2014

< [[::Category:Functions|Category:Functions]]

A function added by the Fallout Script Extender.

Description

Returns the base form of the Nth item in a container.

Syntax

[help]
(baseform) Container.GetInventoryObject index:int 

Or:

(baseform) Container.GetNthObject index:int

Example

ref rItem

set rItem to PlayerREF.GetInventoryObject 21

Often you may wish to use this in a loop, to go through every item in an inventory:

int x
ref rItem

let x := PlayerREF.GetNumItems

while x > 0
    let x -= 1 ; decrement x, the first item is '0'
    let rItem := PlayerREF.GetInventoryObject x
    ; do something
loop

Notes

  • Beware removing items from a container within a loop, because it may change the index of those later.
  • Multiple instances of the same base form in a container are considered as just one item by the function.

See Also