Caveats
CK Wiki - Notes
- Keep in mind that if you don't need the exact index of a formlist entry, the native FormList.HasForm(...) will always be the quickest method to find out whether the list contains an entry--far quicker even than a binary search like the one above.
- A created reference does not become persistent by virtue of being added to a FormList. If you try to retrieve the reference from the FormList when it is not loaded and not persistent, you will get an incorrect result or no result.
Parameters
intaiIndex
CK Wiki Description
The index in the list we want to fetch the form from
- The index is 0-based. If a list has 3 items in it, valid indices are:0, 1 and 2
Examples
Int iIndex = kFormList.GetSize()
While iIndex > 0
iIndex -= 1
Debug.Trace("Form " + iIndex + " is " + kFormList.GetAt(iIndex))
EndWhileInt Function iGetFormIndex(FormList akList, Form akMember) Global
If akList.HasForm(akMember)
Int iIndex = akList.GetSize() ; Will always return a finite value
While iIndex > 0
iIndex -= 1
If akList.GetAt(iIndex) == akMember
Return iIndex
EndIf
EndWhile
EndIf
Return -1 ; Either the form is not in the list, is not currently loaded if non-persistent
EndFunctionInt Function GetFormIndexOrdered(FormList akList, Form akMember) Global
Int iFormID = akMember.GetFormID()
Int iMin = 0
Int iMax = akList.GetSize() - 1
While iMax > iMin
Int iMid = (iMin + iMax) / 2
If iFormID > akList.GetAt(iMid).GetFormID()
iMin = iMid + 1
Else
iMax = iMid
EndIf
EndWhile
If (iMax == iMin) && (iFormID == akList.GetAt(iMin).GetFormID())
Return iMin
Else
Return -1
EndIf
EndFunctionAuto-Generated Example
int myInt__aiIndex
Form returnedValue = myFormList__toCallFunctionOn.GetAt(myInt__aiIndex)