Talk:GetAt - FormList

From the CreationKit Wiki
Jump to navigation Jump to search

The example for GetFormIndex may cause serious issues. I agree that under normal conditions it should be just perfect but that's not the case in papyrus. The function as in example may cause an endless loop in some situations and it could become a problem if people just copy that example from here without proper testing their mod. See http://forums.bethsoft.com/topic/1413484-getformindex-ck-wiki-style-issue-form-not-found-when-in-the-list What JustinOther posted there is just what I mean too and if no objections and noone else will change the main page I will change it with:

Int 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
EndFunction

LukeH (talk) 07:59, 12 October 2012 (EDT)