TList.First and TList.Last

BlitzMax Forums/BlitzMax Programming/TList.First and TList.Last

Howdy,

I'm not getting the clue how to work with an object from a TList addressed by TList.First or TList.Last
Help only says those methods return objects but trying to bind them like you do with the for...eachin doesn't work (item:type = TList:Last)

Say I have got an object enemy with field image saved in EnemyList.
Using a loop you have access by "for e:enemy = eachin EnemyList" and objects are accessible within the loop by e.image etc.
How does this work when I wanna address the last object in the list with EnemyList.Last?

myenemy=enemy(tlist.last())

I believe you have to cast to the type it is, since tlist just stores pointers to objects.

Why doesn't it cast automatically when it does for int->string

Dunno. I didn't write it. ;)

Thanks Lurie, this works!

Another way is to create an object and cast it but this would end up in two steps instead of this one step! =8)

Why doesn't it cast automatically when it does for int->string
Because BlitzMAX TLists are not typesafe.