Linked List Problem
BlitzMax Forums/BlitzMax Programming/Linked List Problem
| ||
Here's my dilemna. I have a type and two of the fields are TLists. I need them to talk to each other so when I change a value in one list, it changes in the other. I need to keep them non-global and in the Type. Some code example: Type Blah Field List1:TList = New TList Field List2:TList = New TList End Type |
| ||
Could you have a method inside Type Blah that handles the various list operations? It's good to do that, anyway. I forget what the term is, but one thing done with OOP is to have methods to change any variables in a Type. That way you can make changes to how data is stored fairly easily, looking nowhere except for in the Type definition. |
| ||
Hmm...testing. I think I'm a victim of my own complexity, if that makes sense. This sucks...If I have global lists I can change object data in one list and it affects the other. But I can't figure out how to do that with the above configuration. :( |
| ||
Ugh...I found the bug. A line I put in for testing and I even commented that I needed to take it out... |
| ||
can you post your solution? |
| ||
Sure. Remember that TBlahs are stored in List1 and List2.Type TSomething Field List1:TList = New TList Field List2:TList = New TList End Type Local this:TBlah For this = Eachin List2 If this.value = 100 KillThisBlahInList1( this ) self.List2.Remove( this ) Endif Next ... Method KillThisBlahInList1( that:TBlah ) Local this:TBlah For this = Eachin List1 If this = that self.List2.Remove( this ) Exit (or Return False) Endif Next End Method |
| ||
Can't you simply do this ?Method KillThisBlahInList1( that:TBlah ) self.List1.Remove(that) End Method :-) |
| ||
yes. especially the above would be a total overkill. remove will loop through the list anyway so looping to find the object and then call remove on the list instead of a tlink means twice looping for the same thing |
| ||
Do the 2 lists contain exactly the same objects? |