The question is, why you need the link at all. TList has all functionality to operate without touching its implementation as it should be in OO.
Let's say I do:
For ThisSprite = Eachin Sprite.SpriteList
Next
How, inside that loop, would you get the next sprite, and the previous sprite in the list?
(Note: Using ToArray, or a repeat loop is not an option here. I'm asking how you would do it from within that loop, not how you would implement it differently or better.)
And on your note above: Thats simply wrong.
It returns the first link as addfirst returns the link as well (insertafterlink / insertbeforelink returns a TLink as you clearly see in their implemenation)
But this assumes that your compare method is done correctly, otherwise it will return crap.
I didn't understand a thing you just said.
Addfirst returns a TLink. Correct.
But what you pass to it is a "Value". And that "Value" here is a pointer to a sprite.
FindLink's help says it finds the "Value" of a link.
But the "Value" of a link is the pointer to the sprite.
The Value of the Sprite is the sprite's Order, because of how I implemented my Compare() method.
What Findlink is actually finding is the Value of the Sprite, which is to say, the Value of object the the Value of the Link points to.
And sadly, your implementation simply sux in returning 0 which means "equal", so you will never see anything different than 0! (if you do not have a compare in your type then it must even be reference pointer equal to get a compare = 0!)
Once again, I can't understand a thing you're saying.
First of all, I'll have you know, I copied that implementation from one of the examples.
Method Compare(OtherObject:Object)
Local OtherSprite:Sprite = Sprite(OtherObject)
If OtherSprite = Null Then Return 0
Return Order - OtherSprite.Order
End Method
Second of all, I know it's correct. Explain to me how the return value there can never be anything BUT 0?
Sprite 1 order - Sprite 2 order = Result
----------------------------------------
5 - 5 = 0 (EQUALS)
5 - 1 = 4 (GREATER THAN)
5 - 7 = -2 (LESS THAN)
Looks like it should work fine to me.
Hope your "vamp hunt" on BM is soon over as you get used to how it works and not interpreting things into the source that are not there.
if there were bugs in the main modules like TList, we would have spoted them quite some time ago!
When I posted, I didn't really think there was a bug, I did actually think I did something wrong.
But let me ask you something.
If the help file says a function does something, and the function doesn't do what the help file says it should do, does that mean the function is broken, or the help file is wrong?
In this case, I would say the help file is wrong. But really, you could look at it either way. That's why I kept insisting the function was broken. It does NOT behave the way the help file says it does.
Now that I know more about it, it's clear the function works the way it was INTENDED to work, but the help file just describes how it works wrong.
Btw, I don't think ANYONE here would argue that the HELP FILES are perfect, and that all "bugs" with THOSE have been found. And that is what caused this whole mess.
So yes, I admit, I used FindLink wrong. But I used it wrong because I used it how the help file said it works. The help file description needs to be changed.
Also:
Sswift:
So is there any function which DOES find the link with the specified value?
Dreamora:
Yeah:
function getLink:tlink (list:tlist, value:object)
local temp:tlink = list.firstlink()
"Yeah" is incorrect. I searched linkedlist.bmx, and there is no GetLink() function.
I didn't ask if it was possible to make such a function. I asked if there was one. In the language. In the help file. There isn't. I know you can make one yourself, but that's not what I was interested in. The whole point of trying to use it in the first place was becuase I was lazily trying to save time instead of coding a custom repeat loop for looping through the linked list. (Which is what I ended up doing.)
Btw, I think we're having a bit of trouble communicating here. So don't get too frustrated with me.