Difference between revisions of "Talk:GetNthRef - Cell"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Terra Nova2
m (Removed bit about example not working. Run-time error on my end.)
imported>Terra Nova2
Line 1: Line 1:
== Handling references without names ==


This function as well as [[GetNumRefs - Cell]] doesn't take names in account when you're looking for a specific type. Furthermore, if you narrow down the amount in order to fit an array(not doing so will take the array out of bounds) it will ''also'' fill the array with forms that don't have a name, if you're trying to fill an array based on names.
For handling the ones without names.. do this:
<source lang="papyrus">
Actor property PlayerRef auto
Cell kCell = PlayerRef.GetParentCell()
Int n
Int iRefs = kCell.GetNumRefs(38) ; trees
Function SomeFunction()
        While (n < iRefs)
                ObjectReference kRefs = kCell.GetNthRef(n, 38)
                if kRefs.GetBaseObject().GetName() ; by default, strings are true if they a not empty.
                    ; add to alias, array, etc. ONLY filled with references that have names!
                endif
                n += 1
        EndWhile
EndFunction
</source>

Revision as of 07:10, 28 February 2015

Handling references without names

This function as well as GetNumRefs - Cell doesn't take names in account when you're looking for a specific type. Furthermore, if you narrow down the amount in order to fit an array(not doing so will take the array out of bounds) it will also fill the array with forms that don't have a name, if you're trying to fill an array based on names.

For handling the ones without names.. do this:

Actor property PlayerRef auto

Cell kCell = PlayerRef.GetParentCell()
Int n
Int iRefs = kCell.GetNumRefs(38) ; trees

Function SomeFunction()
         While (n < iRefs)
                ObjectReference kRefs = kCell.GetNthRef(n, 38)
                if kRefs.GetBaseObject().GetName() ; by default, strings are true if they a not empty.
                     ; add to alias, array, etc. ONLY filled with references that have names!
                endif
                n += 1
         EndWhile
EndFunction