That might make sorting the list easier Dreamora, but it does not enable me to do the task described above, which is to provide a good way to make sure the list is sorted each time the order of a sprite is changed.
I guess I'd have to see what context this is in for it to make much sense. It's just that changing the default behaviour of something is a very delicate procedure. Easy to get wrong, hard to get right.
What context?
I want to be able to do the following:
' Set ship order, and sort list of sprites so the list is in the correct order.
ShipSprite.Order = 10
' Get ship order.
Temp = ShiSprite.Order
The act of setting the field causes a method of the same name to be triggered.
The only problem I can see with this, is that either the field is changed before the method is executed, or it is changed after the method is executed. Either one might be the desired behavior.
The only way around this is to somehow pass the new value to the method, so that we can access the old value and the new value at the same time, and choose whether we even set the order field to be the new value or not.
In other words, Order would be a function, not a field. But it would be a special function. A function which you can assign a value. And that value is passed to the function via a special variable. Also, the function is capable of storing a value permanently. In that way it is like a field. That value could also be accessed in the function from a special variable. And when you call the function and do not assign a value to it, the function would know this. Perhaps NewValue = Null in this case. And as a result of this, the function woukd return StoredValue.
So:
A = Sprite.Order
Function executes method Order, returns value stored in method (StoredValue) that is not lost when the method stops executing.
Sprite.Order = A
Function executes method Order, passes value of A in special variable NewValue which can be accessed within the function. Function then has the option of setting StoredValue = NewValue, which would be the same as setting a field, or it has the option of doing this before, or after it performs some other operation given the new data.
Right now, the best I know of that you can do is this:
A = Sprite.Order
Sprite.Order(A)
You can't do:
Sprite.Order = A
Also, in the first two examples, you're not storing a value in a field or method called Order, you have to have a Method called Order, and a field called something else, like _Order so the method, which sorts the list when you change the order, has something to store the value in.
Now is this more obfusticated? Perhaps, on the type level, there would be some confusion about what the Method is doing if people don't know what a ... (damn, there's a word for a variable in a function which you declare and it sticks around after the function ends, but I just can't remember the name of it) ... is, but there also would not be a second variable with almost the same name as the method in the type to cause confusion. And the user interface outside the type for setting the value would be neater.