Navigation

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

    Dynamic array sizes?

    Coding
    4
    7
    481
    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.
    • N
      Nisse5 F last edited by

      Is it possible to create arrays of dynamic sizes (such as expanding/truncating the size of an existing array, basically treating it as a collection)? If so, how?

      1 Reply Last reply Reply Quote 1
      • M
        MikeDX last edited by

        You can do the following

        
        myarray = []
        
        myarray[1] = 1
        myarray[2] = 2
        myarray[3] = 3
        ....
        
        myarray[100] = 100
        
        N 1 Reply Last reply Reply Quote 0
        • N
          Nisse5 F @MikeDX last edited by

          @MikeDX Thanks, but I get a hard crash when I try that with nested struct arrays. I can't reproduce the crash in a smaller example, but I get a strange error ("Unrecognized type error") in the following example. It might be the same issue that produces the hard crash in the larger program.

          struct struct1
             int i = 1
          endstruct
          
          struct ownerstruct
             struct1 s = []
          endstruct
          
          ownerstruct os[10]
          
          struct1 mys
          mys.i = 2
          os[5].s[4] = mys
          
          loop
             clear
             print(os[5].s[4].i)
             update()
          repeat
          

          If I change the

          struct1 s = []
          

          into a fixed array, it works:

          struct1 s[10]
          
          1 Reply Last reply Reply Quote 0
          • Discostew
            Discostew F last edited by

            What if you assigned it to os[5].s[0]?

            N 1 Reply Last reply Reply Quote 0
            • N
              Nisse5 F @Discostew last edited by

              @Discostew said in Dynamic array sizes?:

              What if you assigned it to os[5].s[0]?

              That works!
              (Still doesn't solve the hard crash in my larger program though.)

              Discostew 1 Reply Last reply Reply Quote 0
              • Discostew
                Discostew F @Nisse5 last edited by

                @Nisse5 said in Dynamic array sizes?:

                @Discostew said in Dynamic array sizes?:

                What if you assigned it to os[5].s[0]?

                That works!
                (Still doesn't solve the hard crash in my larger program though.)

                Methinks that to make it dynamic, it needs to grow from the lowest to the highest without jumping over any steps. Before the step where you call os[5].s[4] = mys, what happens if you call the previous ones like this - "os[5].s[y] = []", where "y" is index 0, 1, 2, and 3 (like in a FOR loop)?

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

                  There seems to be something wrong with arrays that causes type errors under heavier usage, will make another bug post about it shortly

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