how to get first object in the list?

BlitzMax Forums/BlitzMax Programming/how to get first object in the list?

gameproducer(Posted 2008) [#1]
What's wrong with this... when I try to do:
Local template:TTemplate = TTemplateManager.templateList.First


I get the following error:
Compile Error: Unable to convert from 'Object()' to 'TTemplate'
Build Error: failed to compile D:/Dead Wake/development/_code/game.bmx


But all works (?) when I do:
for Local template:TTemplate = EachIn TTemplateManager.templateList
   TCharacterManager.CreateCharacter(template)
Next


TTemplate is my own class (Type TTemplate with some fields), and TTemplateManager has "Global templateList:TList = CreateList()"

What's the problem with 'first'? (and how to get the first item in this list?)


GfK(Posted 2008) [#2]
You need to cast the object to its original type:
Local template:TTemplate = TTemplate(TTemplateManager.templateList.First())



gameproducer(Posted 2008) [#3]
Now it said:

Compile Error: Unable to convert from 'Object()' to '<unknown>'
Build Error: failed to compile D:/Dead Wake/development/_code/game.bmx


?


REDi(Posted 2008) [#4]
Did you forget the parenthesis on .First()?


gameproducer(Posted 2008) [#5]
yep :)

...testing

EDIT: And it works. Thanks!