Method Last Problem

BlitzMax Forums/BlitzMax Beginners Area/Method Last Problem

Ant(Posted 2006) [#1]
Hi, having an issue with the last method. I have a list called ballList which contains a list of TBall types. I'm trying to get the last TBall in the list using the following:

Local tempBall:TBall
tempBall = ballList.last()

However, when I build it says 'Unable to convert from Object to TBall'

Sorry, but just cant see what I'm doing wrong - other examples seem to suggest I'm using this correctly! Can anyone help?
thanks guys


Ant(Posted 2006) [#2]
Ok, sorry guys I see you have to do this:

Local lastObj:Object
lastObj= FirstPath.ballList.last()

which I am finding confusing as the object in the list is type TBall....can anyone help me understand?


Dreamora(Posted 2006) [#3]
tempBall = TBall(ballList.last())


Ant(Posted 2006) [#4]
So it returns an object and you are casting it to type TBall?


Dreamora(Posted 2006) [#5]
Correct.
Thats what the method header of first and last specifies as well :-)


Ant(Posted 2006) [#6]
Sorry Dreamora - I'm new to a lot of this and things that perhaps should be obvious to me just arent at the moment - very frustrating for me and probably annoying for you guys ;-)

When you say the header do you mean the help text or are you talking about an actual header file? If so where can I find these (see what I mean ;-)

Thanks again


Brucey(Posted 2006) [#7]
In the docs it has this for last() :
Method Last:Object()

The part between the ":" and the "()" is the type returned by the method. In this case, it returns the type "Object".
Unless you have a list of Objects, you will have to cast this back to its actual type.