Difference between revisions of "GetAt - FormList"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Jimhsu
imported>Cipscis
(→‎Examples: Small improvements to newly added "GetFormIndex" example, based on a version of it I'd written earlier)
Line 29: Line 29:


<source lang="papyrus">
<source lang="papyrus">
; Gets the index of item f in formlist l, returns -1 if not found.
int Function GetFormIndex(FormList List, Form Member) global
int function getFormIndex(FormList l,Form f)
{Gets the index of Member in List. Returns -1 if not found}
int r = -1
if (!List.HasForm(Member))
int c = 0
Return -1
while (c < l.getSize())
endif
if (f == (l.GetAt(c) as Form))
 
r = c
int Index = 0
EndIf
While (List.GetAt(Index) != Member)
c += 1
Index += 1
EndWhile
EndWhile
return r
 
Return Index
EndFunction
EndFunction
</source>
</source>

Revision as of 04:57, 19 February 2012

Member of: FormList Script

Returns the form at a specified index in the list.

Syntax

Form Function GetAt(int aiIndex) native

Parameters

  • aiIndex: 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

Return Value

Returns the form at index aiIndex, none in case of error (such as wrong index value)

Examples

; Print out the forms in the list
FormList property list auto
int index = 0
While (index < list.GetSize())
  Debug.Trace("Form " + index + " is " + list.GetAt(index))
  index = index + 1
EndWhile
int Function GetFormIndex(FormList List, Form Member) global
{Gets the index of Member in List. Returns -1 if not found}
	if (!List.HasForm(Member))
		Return -1
	endif

	int Index = 0
	While (List.GetAt(Index) != Member)
		Index += 1
	EndWhile

	Return Index
EndFunction

See Also