TList returns Object, but i want TMyGameObject
BlitzMax Forums/BlitzMax Beginners Area/TList returns Object, but i want TMyGameObject
| ||
hi guys! My query is regarding TList. Is there any way to cast a object returned from Tlist to its original object? I do this: 1. Add a Type of TBattleCruiser to a Tlist. '// implicitly here MyBattleCruiser is a Type already in existance in code. TheTlist:TList = new TList TheTlist.AddLast(MyBattleCruiser) 2. Do some stuff 3. Then later on i want to return a object of type TBattleCruiser such as MyBattleCruiser = TheTlist.Last() But, that doesnt work coz BlitzMax complains at compiletime that TheTlist.Last() would return Object. Is there any way to cast Object to TBattleCruiser? I know the C# syntax would be: MyBattleCruiser = (TBattleCruiser)objTheTlist.Last() How do i get the same result as C#, but with BlitzMax? TIA! |
| ||
MyBattleCruiser = TBattleCruiser(TheTlist.Last()) |
| ||
Funny thing is if you did this:For Local mbc:TBattleCruiser = eachin TList mbc.dosomething() Next It works fine, no typecast needed. |
| ||
That make sence tho grey. I would imagine that it crashes if TList didnot contain a downcast object of TbattleCruiser |