Problem Returning Type
BlitzMax Forums/BlitzMax Beginners Area/Problem Returning Type
| ||
Hi I am playing around with blitzmax but i am having a problem with returning a custom type back from a list below is the code in theory the line print a.ReturnFirstItem.y should return 4 but it says Compile Error: Identifier 'x' not found Can some one see where i am going wrong as it is doing my head in. Thanks Type TestType Field x:Long Field y:Long End Type Type TestType2 Field TypeList:TList'our list 'add a type Method AddType(x:Long,y:Long) Local TempType:TestType=New TestType TempType.x=x TempType.y=y TypeList.addlast TempType End Method 'Draw the collection Method DrawList() For Tobj:TestType=EachIn TypeList Print Tobj.x + " " + Tobj.y Next End Method '============================================= 'This is the bit that is giving me a head ache '============================================= Method ReturnFirstItem:TestType() Return TypeList.First() End Method Method CreateSingleItem:TestType() Local TempType:TestType=New TestType TempType.x=5 TempType.y=8 Return TempType End Method Method New() 'Create Our List If TypeList= Null Then TypeList:TList=CreateList() EndIf End Method 'return back its Function Create:TestType2() Local TempType:TestType2=New TestType2 Return TempType End Function End Type a:TestType2= TestType2.Create() a.AddType(1,4) a.AddType(1,3) a.DrawList() print a.ReturnFirstItem.y |
| ||
Method ReturnFirstItem:TestType() Return TestType(TypeList.First()) End Method |
| ||
That is a pretty lousy error message for trying to use a member of a function pointer which BlitzMax thinks ReturnFirstItem is referring to if you miss out the brackets. Try: Print a.ReturnFirstItem().y |
| ||
Cheers guys it easy when you know how |