Probbably silly question about typelists
BlitzMax Forums/BlitzMax Beginners Area/Probbably silly question about typelists
| ||
| In blitz3d you could select objects in the list with commands like First, After and Before. Is there any way to do this with typelists in blitzmax? Thank you for any clues ;) im pretty new to this max stuff |
| ||
| Yeah, but you'll have to use TLinks for manual navigation. the question you should be asking instead, is "why would you want to"? |
| ||
| Becourse I dont know better dammit ;) Well there other ways do the things i imadigned i know. Its just that I sorta missed atleast "First" |
| ||
| Hi SpaceGuy (long time no see) I miss the simplicity of previous Blitz versions as well. But you can achieve the same end result in BlitzMax, just not as easily, because you have to navigate thru the list using the TList commands and then use other commands to check what Object/Type the TLink points to. A lot more fiddly, but you kindof get used to it. Also, in some instances using Arrays might be better/easier, obviously only for linear lists, and with the potential for a little loss in speed. |
| ||
| Hi space_guy. Getting the first and last objects is quite easy: object=MyList.First() or object=MyList.Last() The equivilents for After and Before are fairly easy to use. Use the FirstLink() and LastLink() methods of the list to obtain a TLink object. To get the value stored in that link, use the link's value() method. To get the next link use the link's NextLink() method. To get the previous link use the link's PrevLink() method.
Local myList:TList=New TList
myList.AddLast("Item One")
myList.AddLast("Item Two")
myList.AddLast("Item Three")
Local link:TLink=myList.FirstLink()
While (link)
Print link.value().ToString()
link=link.NextLink()
Wend
|
| ||
I took too long to write this, but I'll post it anyway, it can sometimes help to see multiple uses of things:
Type TMyType
Global List:TList
Field Value:String
Function Create:TMyType(val:String)
Local tempType:TmyType = New TMyType
If Not List Then List = New TList
tempType.Value = val
List.AddLast(tempType)
Return tempType
End Function
End Type
For Local a = 0 To 9
TMyType.Create("test "+a)
Next
'print each value
For Local t:TmyType = EachIn TMyType.List
Print t.value
Next
Print' blank line
Print' guess what?
Print TMyType(TMyType.List.Last()).value
Print TMyType(TMyType.List.First()).Value
|
| ||
| Hello and thank you all. I will take in all the info you supplied. And yes Beaker. Its been quite some time. Thank you all for the red carpet! |