Method Last Problem
BlitzMax Forums/BlitzMax Beginners Area/Method Last Problem
| ||
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 |
| ||
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? |
| ||
tempBall = TBall(ballList.last()) |
| ||
So it returns an object and you are casting it to type TBall? |
| ||
Correct. Thats what the method header of first and last specifies as well :-) |
| ||
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 |
| ||
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. |