Finding an object in a list?

BlitzMax Forums/BlitzMax Beginners Area/Finding an object in a list?

Another way to find an object is to give the object a special id and then use this.


Global mylist:TList=CreateList()

Type fruit
	Field name$
	Field id = mylist.Count()
End Type

Local f:fruit

f=New fruit ; f.name$="apple"  ; ListAddLast mylist,f
f=New fruit ; f.name$="banana" ; ListAddLast mylist,f
f=New fruit ; f.name$="pear"   ; ListAddLast mylist,f
f=New fruit ; f.name$="orange" ; ListAddLast mylist,f
f=New fruit ; f.name$="peach"  ; ListAddLast mylist,f

f = fruit(mylist.Valueatindex(2))
If f Print f.name$ Else Print "not found"
End