Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    array helper functions

    Beginners
    array
    5
    10
    802
    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.
    • spikey
      spikey F last edited by spikey

      @_JKDOS according to your post about push() and pop() I started doing some simple implementations of these, with the possibilities, that already exist in FUZE4.


      Its maybe helping someone to simplify code or save time (SW-4464-9632-0709), of course its not as efficient, as language supported functions ;-)

      1 Reply Last reply Reply Quote 2
      • Discostew
        Discostew F last edited by Discostew

        You can actually shorten some of that code down. Here's an example of your shift function reduced...

        function shift( a )
        return a[ 1 : ]
        

        What that does is grabs the entirety of the array beginning at the second position (because of base 0), and returns that. Your pop and resize functions can benefit from this as well. Not actually sure if this is meant to be done this way, as this technique has been used for manipulating strings in groups since we can access them like an array (refer to my post in the Hints and Tips thread). However, unlike strings where we can append strings together, we can't with arrays, so functions you have like slice and delete could grab the first portion of the array in one go, but the second part will have to be filled in one element at a time.

        With that said, it would be nice to have built-in functionality of these.

        1 Reply Last reply Reply Quote 4
        • vinicity
          vinicity F last edited by

          Do you gain any performance improvements by doing array operations like Discostew suggested? Or does Fuze still loop through the whole array “under the hood”?

          Is the “:” trick found somewhere in the documentation? It’s a bit cumbersome searching the forum ever time I want to find the usage...

          1 Reply Last reply Reply Quote 2
          • vinicity
            vinicity F last edited by vinicity

            Bye the way, @spikey, those functions are super useful!

            1 Reply Last reply Reply Quote 1
            • spikey
              spikey F last edited by

              @vinicity I could not find the discussion anymore about the array access shortcut. But I know there is one, maybe it answers the "documentation" question (can you help @Discostew ?). Interesting question if it performs better: it could, but also because it returns the value immediately and does not create an additional local variable. Volunteers for a test program?

              1 Reply Last reply Reply Quote 1
              • pianofire
                pianofire Fuze Team last edited by

                Was it this one? https://fuzearena.com/forum/topic/70/hints-and-tips/9

                1 Reply Last reply Reply Quote 3
                • vinicity
                  vinicity F last edited by

                  @spikey, could you share/submit those functions above? Unless you have already, and I missed it?
                  I might throw together a little performance test tonight.

                  spikey 1 Reply Last reply Reply Quote 0
                  • spikey
                    spikey F @vinicity last edited by spikey

                    @vinicity sure, cool. NQ5QBMNDN8

                    xevdev 1 Reply Last reply Reply Quote 1
                    • xevdev
                      xevdev F @spikey last edited by

                      @spikey this will be interesting

                      1 Reply Last reply Reply Quote 0
                      • vinicity
                        vinicity F last edited by

                        I did some quick tests, and it seems that the modified functions are definitely faster. Between 4 and 10 times in my little test scenarios...

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