loop for objects
-
how can i loop for the newest object? i already set up a loop but it always shows a random item, but i just want to loop for the newest.
Thank you very much for your help on this one

-
You know what, I just saw that there is a property OBJPROP_CREATETIME for the objects. I don't know since when this property exists, but I really see it for the first time now. I think I can do something with it, because at the moment the situation is not very good.
So, how it works now. By default MQL sorts objects by name. ObjectsTotal() gives us the number of objects, but then when we start to load them one after another we see that they are sorted by name, not by time of creation. That's why in "For each Object" you can see A-Z and Z-A sorting methods.
And this type of sorting works in theory, because object names are normally made out of some text (prefix) + unique number at the end. And because that unique number for each next object is +1 from the number of the previous object, as a result you kinda have sorting by time.
But there is one ugly problem. Let's say you have objects with names Arrow 1, Arrow 2 and Arrow 10. What you think is "Okay, they will be sorted like this - 1, 2 and 10". But no, they will be sorted like this - 1, 10 and 2 at the end. That's why it's better to work with names that have bigger numbers.
It will probably be also ugly if I decide to put that property OBJPROP_CREATETIME into the game. Because then I will need to first get the creation time of all objects, put all these times in some array, sort that array and start picking objects out of that array. Which will make everything much slower. I didn't tested it and I don't know how much slower, but it will be slower.
-
@fxdreema said in loop for objects:
You know what, I just saw that there is a property OBJPROP_CREATETIME for the objects. I don't know since when this property exists, but I really see it for the first time now. I think I can do something with it, because at the moment the situation is not very good.
So, how it works now. By default MQL sorts objects by name. ObjectsTotal() gives us the number of objects, but then when we start to load them one after another we see that they are sorted by name, not by time of creation. That's why in "For each Object" you can see A-Z and Z-A sorting methods.
And this type of sorting works in theory, because object names are normally made out of some text (prefix) + unique number at the end. And because that unique number for each next object is +1 from the number of the previous object, as a result you kinda have sorting by time.
But there is one ugly problem. Let's say you have objects with names Arrow 1, Arrow 2 and Arrow 10. What you think is "Okay, they will be sorted like this - 1, 2 and 10". But no, they will be sorted like this - 1, 10 and 2 at the end. That's why it's better to work with names that have bigger numbers.
It will probably be also ugly if I decide to put that property OBJPROP_CREATETIME into the game. Because then I will need to first get the creation time of all objects, put all these times in some array, sort that array and start picking objects out of that array. Which will make everything much slower. I didn't tested it and I don't know how much slower, but it will be slower.
is there any update on this issue? or is there another way to get the newest, since i am still struggling with the names, an option to get the newest object will be a lot better! or is there a way with a custom code to get around ?
thank you very much for your answer!!
-
@fxdreema
emmm...
if the sequence of Arrow 1,Arrow2,Arrow10 is wrong
what about the Arrow 000001,Arrow 000002,Arrow 000010