fxDreema

    • Register
    • Login
    • Search
    • Back to the main page
    • Categories
    • Recent
    • Tags
    • Popular
    • Search

    loop for objects

    Questions & Answers
    3
    4
    2440
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • bk7
      bk7 last edited by

      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 😄

      1 Reply Last reply Reply Quote 0
      • fxDreema
        fxDreema last edited by fxDreema

        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.

        bk7 Z 2 Replies Last reply Reply Quote 0
        • bk7
          bk7 @fxDreema last edited by

          @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!!

          1 Reply Last reply Reply Quote 0
          • Z
            zgbl @fxDreema last edited by

            @fxdreema
            emmm...
            if the sequence of Arrow 1,Arrow2,Arrow10 is wrong
            what about the Arrow 000001,Arrow 000002,Arrow 000010

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post

            Online Users

            J
            T
            J
            B

            22
            Online

            146.7k
            Users

            22.4k
            Topics

            122.6k
            Posts

            Powered by NodeBB Forums | Contributors