CountLinkedRefChain - ObjectReference

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)

SyntaxEdit

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

ParametersEdit

  • 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 ValueEdit

The total number of linked refs chained together or maxExpectedLinkedRefs, whichever is less.

ExamplesEdit

; Count the number of refs in a linked ref chain to us
int numLinkedRefs = countLinkedRefChain()

See AlsoEdit