Getting First Object in type list

BlitzMax Forums/BlitzMax Beginners Area/Getting First Object in type list

Rico(Posted 2008) [#1]
Hi - I've been iterating through type lists in my programs - to display images and do collision checks. However I now need to do some more specific stuff, and I am struggling. Here's an example of what I want to do.

Type carrot
	Field variety:String
EndType

carrot_list:TList =New TList

'--------- Add Carrots to list ---------------------
c:carrot=New carrot
c.variety="Orange"
carrot_list.addlast c

c:carrot=New carrot
c.variety="Black"
carrot_list.addlast c

'---------get first carrot in list

c:carrot=carrot(carrot_list.first)


Basically I can't work out how to get the first object in the list. This code fails on the final line ( I get an errror). Evidently I need to do some casting, but I doing it wrong. Help Please!

Rico


GfK(Posted 2008) [#2]
c:carrot = carrot(carrot_list.first())



Rico(Posted 2008) [#3]
Easy when you know how! Thanks Gfk :)


Czar Flavius(Posted 2008) [#4]
I wouldn't store varieties as strings.. what if one is "Black" and one is "black" by accident?

Have a TVariety type, with a string field for name, and each carrot has a TVariety. Then you only store the info of the name once :)