position of objects in list

BlitzMax Forums/BlitzMax Programming/position of objects in list

Kernle 32DLL_2(Posted 2005) [#1]
hi

I'm looking for a procedure to get the position of an object in a list. Nevertheless i have got no result. Please help me


Rimmsy(Posted 2005) [#2]
There's the simple way:
' will return the index of the object
' will return -1 if the object is not in the list

function findPositionOfObject(lookingFor:object,theList:Tlist)
if listcontains(theList,lookingFor)=0 then return -1
local c=0
for local i:object=eachin theList
     if i=lookingFor then return c
     c:+1
next 
end function



taxlerendiosk(Posted 2005) [#3]
There's a ListFindLink method in TList... but TLinks don't have a GetIndex method. Is there any reason they couldn't? Maybe that could go in the next version.