getFormIndex (CK wiki style) issue: form not found when in t

Post » Mon Nov 19, 2012 1:18 pm

Disclaimer: I've seen a few topics by searching the forum involving getFormIndex but from what I seen the focus on reply was finding an alternate solution and not discussing the root issue, sorry if I missed something.

So the function as seen at http://www.creationkit.com/GetAt_-_FormList
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

I was using it with ObjectReferences and I'm 100% sure the object is in the list and at index 0 in my test. It passes the HasForm check thous not returning -1 but the while condition is never met.
Not working either: List.GetAt(Index) as ObjectReference != Member as ObjectReference
Working: List.GetAt(Index).GetFormID() != Member.GetFormID()

So please help in figuring what the *** happens in the example, not by trying to provide alternative solutions that will avoid completely that condition check.

Another side issue of the bug in the given example is that the index will go over the list size and continue without an error. Again, I know how to change the function to avoid that...but what's the gain if the index is not found if it should be. I'm curious here just if someone tested and is really an endless loop or it will stop somehow at an absolute max size of the form lists or something.

Thanks
User avatar
Alexandra Louise Taylor
 
Posts: 3449
Joined: Mon Aug 07, 2006 1:48 pm

Post » Mon Nov 19, 2012 5:55 pm

Try:
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-persistentEndFunction
If a member in a FormList is not persistent and isn't loaded, it'll not show up reliably and that function could loop forever if the member ceases to be loaded before the Int is returned.
User avatar
Bad News Rogers
 
Posts: 3356
Joined: Fri Sep 08, 2006 8:37 am

Post » Mon Nov 19, 2012 11:27 am

If a member in a FormList is not persistent and isn't loaded, it'll not show up reliably and that function could loop forever if the member ceases to be loaded before the Int is returned.
Yeah, that would fix the endless loop, fixing that was no problem. Still won't fix the index finding (unless "!=" is bugged and "==" works)
The item I searched for is a book in player inventory and the code is called from "onRead" event. Does that mean "is not persistent and isn't loaded"?
Long ago on my first mod I had an issue with forms in lists when leaving the area but in that case the getAt returned none and getFormID returned 0. In the current case getAt doesn't return none, it's getFormID is the same as the one of the item I look for, thus List.GetAt(Index).GetFormID() != Member.GetFormID() ends up false and loop ends. This is why I believe the issue is different in this case.
User avatar
Tina Tupou
 
Posts: 3487
Joined: Fri Mar 09, 2007 4:37 pm


Return to V - Skyrim