Tiny Help with TLists
BlitzMax Forums/BlitzMax Beginners Area/Tiny Help with TLists
| ||
I have a main TList that has all my objects in it. Then I have a second TList that I'm using to also track the same objects that are in a certain state. The problem is how do I get a specific object in a list so I can alter it's properties? I see the MyList.Last command but I'm not sure how I can actually get the last item. If I do a f:MyObject = MyList.Last it doesn't work. So basically the question is what is the correct syntax for getting an object from the list so I can change it's properties. Any help is appreciated. |
| ||
You have to cast the object back to you MyObject, (I think), so I would guessf:MyObject = MyObject (MyList.Last)Im just guessing, so wait until the big boys answer, or just test it I suppose |
| ||
f:MyObject = MyObject(MyList.Last() ) (or .first() ) first() and last() are methods, not fields. Blitz methods and functions that return something need to have () to return something. (you can call them without the () if they do not return anything without any problem) |
| ||
What i do is have a seperate field in my type called "id". I assign an id to an object then when i need to manipulate the object I check if the id matches and make the necessary changes. |
| ||
hay that means I was nearly right. ;) ;) ;) |
| ||
Ok now what if I have the object in the 2nd list and i change a value. Will the same object in the first list be effected? |
| ||
Yes. The entry in the both lists is simply a pointer to the same single object.Type ttest Field x End Type temp:ttest = New ttest temp.x = 5 list1:TList = CreateList() list2:TList = CreateList() ListAddLast list1 , temp ListAddLast list2 , temp newtemp:TTest = ttest(list2.last() ) newtemp.x = 10 For all1:ttest = EachIn list1 Print "Value in list1 : " + all1.x Next For all2:ttest = EachIn list2 Print "Value in list2 : " + all2.x Next |
| ||
Excellent! Now how can I use the object from one list to target the same object in the other list? |
| ||
You just point the link to the same object |
| ||
Not using Links but I found a workaround. Thanks for the help all. =) |