TList : AddLast etc...
BlitzMax Forums/BlitzMax Programming/TList : AddLast etc...
| ||
Hi I'm a little bit lost whith the bmax tlink commands (like addlast addfirst from blitz3D) Anybody can help me ? Original code (blitz3D) : My blitzmax code : |
| ||
why do you not just use for local t:thingyT = eachin thingyTList ... |
| ||
Try changing AddLast to AddFirst and doing something like this for you update code:Local Mx:Int=MouseX() Local My:Int=MouseY() Local newlist:TList = thingyTList.Copy() For Local this:thingyT = EachIn thingyTList If (mx >= this.x) And (mx <= (this.x+this.width-1)) And .. (my >= this.y) And (my <= (this.y+this.height-1)) newlist.Remove( this ) newlist.AddFirst( this ) EndIf Next thingyTList.Clear() thingyTList = newlist newlist = Null ' precaution I have to admit though, I'm somewhat confused. You wrote a GUI for BMax, and you're not sure how linked lists work? O_o |
| ||
Might explain why users of the library opted it to tripple the speed ^^ |
| ||
Pure Cane Soda : You are right it's strange :) Maybe an alien instead me, wrote the library? :) i understand the method EachIn without problem but the approach via while / Wend and tlink is maybe usefull too? Thanks for your help :) Edit : But as you can see the list in the blitz code is browsed from the last to the first. the method eachin browse the list from start to end. This is why I am asking the question about the tlink :) Dreamora : What? :/ |
| ||
Filax, I think you are looking for TLink.PrevLink:TLink() and TList.InsertAfterLink:TLink(value:Object, pred:TLink) |
| ||
You are right David! but the doc do not really help me :/ |
| ||
Does this help? Pseudocode: Local link:TLink = List.LastLink() While link If TListItemType(link.Value()) = ItemWeAreSearchingFor List.InsertAfterLink(NewListItem,link) Exit EndIf link = PrevLink() Wend |
| ||
the approach you use there makes only partially sense. what makes more sense is to store the TLink you get from addFirst / AddLast when adding an element to the object that you added. That allows you to get the previous / next element of each element in the list as well as removing it instantanous from the list if needed. moving it around the list is as well no problem |
| ||
I'll try others methods, thanks for help :) |
| ||
here is an extended list I did where you can go from any link forwards or backwards http://www.blitzbasic.com/codearcs/codearcs.php?code=1807 |
| ||
Thanks Dmaz i'll take a look ;) |
| ||
Did you know, that eachin is that intelligent to only return values of a certain type? I didn't until now... Until now I thought that obj will be Null for TB-objects. Blitzmax is such a lovely language! |