Navigation

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

    re-sizing an array

    Beginners
    3
    5
    366
    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.
    • J
      JonnyLaw F last edited by

      is there any way to change the size of an array?
      in the other programming language i know, processing, it is done like this

      // declare array
      int[] name;

      //could also be declared like this, but you have to have the size with this one
      int[] name = new int[14]

      //main loop
      void draw() {
      //new size
      name = new int[23];
      }

      is there anything similar in FUZE?

      1 Reply Last reply Reply Quote 0
      • Dave
        Dave Fuze Team last edited by Dave

        Arrays expand dynamically in FUZE. So, you can do:

        myArray = []
        for i = 0 to 10 loop
            myArray[i] = 1
        repeat
        
        myArray[15] = 1
        

        And Fuze will create elements up to the 15th, filling each element in with void values. This will give you some trouble if you try do things with that value, such as printing for example.

        You can also do:

        array myArray[10]
        
        myArray[15] = 1
        

        Works exactly the same way!

        J 1 Reply Last reply Reply Quote 1
        • J
          JonnyLaw F @Dave last edited by

          @Dave what about making an array size smaller? how would you do that?

          1 Reply Last reply Reply Quote 1
          • PB____
            PB____ last edited by

            I've shared a project with ID X7R53MND1Z

            That contains a function called splice that you could copy into your project.

            You could call it like this:
            output = splice([array], positionToRemove, numberOfElementsToRemove, [array with elements to add in stead])
            output.result // contains the modified array

            so for example

            output = splice([0,1,2,3,4], 2, 1, [])
            

            would lead to output.result = [0,1,3,4] so from [0,1,2,3,4] the element at position 2 (coincidentally also the value 2) is removed (1 in the function call means remove 1 element, the empty array at the end just means you don't want to replace the value with anything else)

            Splicing gives you flexibility in how you want to modify the array. However it does work with making a copy of the array.

            I hope that made sense.

            1 Reply Last reply Reply Quote 2
            • PB____
              PB____ last edited by

              I did find some small bugs that I've fixed (update is pending for review):

              Both with adding elements to the end and with inserting at the start of the array did not go well.

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