Help with Tlist

BlitzMax Forums/BlitzMax Beginners Area/Help with Tlist

You have to cast the generic object into your own object
A modified version of the above example with casting

'FirstLink(), Value() and NextLink()
'Note that Value() and NextLink Methods from Type TLink
'Whereas FirstLink() is a method from Type TList
SuperStrict

Local MyList:TList = CreateList()
Type MyType
	 Field name:String
	 Field X:Int
	 Field Y:Int
	
	 Function Create:MyType(n:String , a:Int , b:Int)
		Local m:MyType = New MyType
		m.name = n
		m.x = a
		m.y = b
		Return m
	End Function
	
End Type

MyList.AddFirst(MyType.Create("Hero" , 10 , 20) )
MyList.AddFirst(MyType.Create("Alien1" , 100 , 320) )
MyList.AddFirst(MyType.Create("Alien2" , 120 , 120) )
Local M:MyType

Local NLink:TLink = MyList.FirstLink() 'get first Link
Repeat
   M=MyType(NLink.Value()) 'Need to convert value from object to your type
   Print M.Name+" is at "+M.x+","+M.y
   NLink = NLink.NextLink()       'Move to the next link in list
Until Nlink = Null                'Null means we've reached the end of the list

This is casting in action
M=MyType(NLink.Value())