TList.First and TList.Last

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

Henry75(Posted 2005) [#1]
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?


LeisureSuitLurie(Posted 2005) [#2]
myenemy=enemy(tlist.last())

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


Curtastic(Posted 2005) [#3]
Why doesn't it cast automatically when it does for int->string


LeisureSuitLurie(Posted 2005) [#4]
Dunno. I didn't write it. ;)


Henry75(Posted 2005) [#5]
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)


FlameDuck(Posted 2005) [#6]
Why doesn't it cast automatically when it does for int->string
Because BlitzMAX TLists are not typesafe.