Difference between revisions of "CountLinkedRefChain - ObjectReference"
Jump to navigation
Jump to search
imported>Jlundin |
imported>Thingy Person (→Syntax) |
||
Line 7: | Line 7: | ||
== Syntax == | == Syntax == | ||
<source lang="papyrus"> | <source lang="papyrus"> | ||
int Function | int Function countLinkedRefChain(keyword apKeyword = None, int maxExpectedLinkedRefs = 100) | ||
ObjectReference CurrentLink = self | |||
ObjectReference NewLink | |||
int NumLinkedRefs = 0 | |||
while(currentLink) && NumLinkedRefs <= maxExpectedLinkedRefs | |||
NewLink = currentLink.getLinkedRef(apKeyword) | |||
if NewLink != self | |||
currentLink = NewLink | |||
NumLinkedRefs = NumLinkedRefs + 1 | |||
Else | |||
currentLink = None | |||
EndIf | |||
endWhile | |||
if NumLinkedRefs >= maxExpectedLinkedRefs | |||
EndIf | |||
return NumLinkedRefs | |||
endFunction | |||
</source> | </source> | ||
Latest revision as of 17:09, 29 June 2013
Member of: ObjectReference Script
This function counts the number of linked refs that are in a linked Ref chain (example: A is linked to B is linked to C - this function will return 3)
Syntax[edit | edit source]
int Function countLinkedRefChain(keyword apKeyword = None, int maxExpectedLinkedRefs = 100)
ObjectReference CurrentLink = self
ObjectReference NewLink
int NumLinkedRefs = 0
while(currentLink) && NumLinkedRefs <= maxExpectedLinkedRefs
NewLink = currentLink.getLinkedRef(apKeyword)
if NewLink != self
currentLink = NewLink
NumLinkedRefs = NumLinkedRefs + 1
Else
currentLink = None
EndIf
endWhile
if NumLinkedRefs >= maxExpectedLinkedRefs
EndIf
return NumLinkedRefs
endFunction
Parameters[edit | edit source]
- apKeyword: Keyword to check ref link against (see GetLinkedRef.)
- maxExpectedLinkedRefs: Maximum number of expected links. The function stops checking after it finds this many or finishes finding all of them. This is used as a safety precaution to premature bail out of a while loop in cases where something in the linked ref chain links back to something in the chain previously, which would result in an infinite loop.
Return Value[edit | edit source]
The total number of linked refs chained together or maxExpectedLinkedRefs, whichever is less.
Examples[edit | edit source]
; Count the number of refs in a linked ref chain to us
int numLinkedRefs = countLinkedRefChain()