Difference between revisions of "GetNextRef"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Haama
(Created)
 
imported>QQuix
(Added usage with GetFirstRefInCell)
 
(9 intermediate revisions by 6 users not shown)
Line 1: Line 1:
__NOTOC__
A command for [[:Category:Oblivion Script Extender|Oblivion Script Extender]]
A command for [[:Category:Oblivion Script Extender|Oblivion Script Extender]]
'''Syntax:'''
'''Syntax:'''
  (reference:ref) GetNextRef
  (reference:ref) GetNextRef


Returns the next reference in the curent cell. [[GetFirstRef]] must be called first; this function uses the cell depth and type passed to [[GetFirstRef]] and returns the next reference matching that type, or zero after the last reference has been returned. This function should only be used within a Label/Goto loop
====When used with GetFirstRef====
Returns the next reference in the curent cell. [[GetFirstRef]] must be called first; this function uses the cell depth and type passed to [[GetFirstRef]] and returns the next reference matching that type, or zero after the last reference has been returned. This function should only be used within a loop.
 
====When used with GetFirstRefInCell====
Returns the next reference in the referenced cell. Works the same as with [[GetFirstRef]], but returns references from a given cell instead of references from the current cell. Ckeck the [[GetFirstRefInCell]] article for additional details
 


'''Example'''
'''Example'''
<pre>ref pDoor
<pre>ref pDoor
...
...
set pDoor to (GetFirstRef 24 1)
set pDoor to GetFirstRef 24 1
Label 1
while (pDoor)
if pDoor
   ; do something with pDoor
   set pDoor to Apple
   set pDoor to GetNextRef
   set pDoor to GetNextRef
  Goto 1
loop</pre>
endif</pre>
Scans the list of doors in the player's current cell and the surrounding 8 cells.
Scans the list of doors in the player's current cell and the surrounding 8 cells.
pDoor is set to an Apple before using GetNextRef because Oblivion doesn't expect the reference of a door, and won't change the variable. So far doors, containers, and magic effects have been found to cause this odd reference variable behaviour, but to be safe always set your reference variable to Apple before using GetNextRef.


==Notes==
==Notes==
*The first reference can change (deleted or moved) by the next frame so [[GetFirstRef]] should always be used first with a Label/Goto loop.
*References can be added to or removed from a cell between frames; for this reason GetFirst/NextRef should be used within a loop that executes within a single frame.
* The order of references as returned by GetFirst/NextRef is essentially undefined. It is not guaranteed that it will remain the same from one frame to the next. As stated above, a loop should be used each time. ''Usually'', however, the first ref is the most recently placed one. It is altogether unwise to rely on this, however.


==See Also==
==See Also==
*[[GetFirstRef]]
*[[GetFirstRef]]
*[[GetFirstRefInCell]]
*[[GetNumRefs]]
*[[GetNumRefs]]
*[[HasBeenPickedUp]]


[[Category:Functions]]
[[Category:Functions]]

Latest revision as of 10:35, 30 September 2012

A command for Oblivion Script Extender Syntax:

(reference:ref) GetNextRef

When used with GetFirstRef[edit | edit source]

Returns the next reference in the curent cell. GetFirstRef must be called first; this function uses the cell depth and type passed to GetFirstRef and returns the next reference matching that type, or zero after the last reference has been returned. This function should only be used within a loop.

When used with GetFirstRefInCell[edit | edit source]

Returns the next reference in the referenced cell. Works the same as with GetFirstRef, but returns references from a given cell instead of references from the current cell. Ckeck the GetFirstRefInCell article for additional details


Example

ref pDoor
...
set pDoor to GetFirstRef 24 1
while (pDoor)
  ; do something with pDoor
  set pDoor to GetNextRef
loop

Scans the list of doors in the player's current cell and the surrounding 8 cells.

Notes[edit | edit source]

  • References can be added to or removed from a cell between frames; for this reason GetFirst/NextRef should be used within a loop that executes within a single frame.
  • The order of references as returned by GetFirst/NextRef is essentially undefined. It is not guaranteed that it will remain the same from one frame to the next. As stated above, a loop should be used each time. Usually, however, the first ref is the most recently placed one. It is altogether unwise to rely on this, however.

See Also[edit | edit source]