Help with Tlist

BlitzMax Forums/BlitzMax Beginners Area/Help with Tlist

Hi I've just started learning blitzbasic and I was wondering if there's a way to manually call the next item in a Tlist?? Without using a for-eachin-next loop?

You can do this
'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() 
MyList.AddFirst("A")
MyList.AddFirst("B")
MyList.AddFirst("C")

Local NLink:TLink = MyList.FirstLink() 'get first Link
Repeat
   Print NLink.Value().ToString() 'Need to convert value from object to string
   NLink = NLink.NextLink()       'Move to the next link in list
Until Nlink = Null                'Null means we've reached the end of the list

================
Output
C
B
A

also see this link on some TList discussion
http://www.blitzmax.com/Community/posts.php?topic=67469

thanks! :)

But how do i convert to different object type other than strings :

i.e the line Nlink.Value().ToString()

can i do something like

entity:TEntity = Nlink.Value() ? (gives me a error saying cant' convert from object to TEntity type atm)

   entity:TEntity = TEntity(Nlink.Value())


But only do it if you're 100% sure it's a TEntity. If it's not a TEntity, you will have a null object.

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())


thanks heaps guys ! works great now :)