Deleting part of an array and reorganising

0 favourites
  • 5 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Does anyone know how I can have and manipulate an array with lots of data, similar to the below representation:

    1,6

    2,7

    3,8

    4,9

    5,10

    So in the above, it's showing a width of 5 and a height of 2. Imagine the height going on for 50. Also, imagine that I want each element to have a depth of 3.

    See, lots of data.

    Now, just using the example, say I want to completely remove the number 3 from the array, and have the number 4 move up 1 element, and the number 5 do the same. Do I need to do this manually, or is there a smart way of manipulating an array in this fashion? As I said, it's going to be a big array with lots of depth elements as well. I'd rather not have to require a manual movement.

    I want the array to recognise when an area of itself is now empty and have its remaining elements move up the array to fill in the blanks. Keep deleting, and you eventually end up with an empty array.

    By the same token, if the array was empty, if you put something in the bottom, it'll quickly make its way up to the top.

    Hope I've made sense...

  • You can use the delete action if you want to it to look like this after removing the x index starting with 3. All the y and z indexes with the same x will be removed too.

    1,6

    2,7

    4,9

    5,10

    Adding values to the array is simple as making the array size one bigger and setting the values at the bottom of the array.

    However if you want just the values directly below three to be shifted up like so:

    1,6

    2,7

    4,8

    5,9

    0,10

    Then you need to define and empty value like 0, and you need to shift it up manually.

    var x=4

    var y=3

    var z=0

    repeat array.width-x times

    --- set array at (x+loopindex, y, z) to array.at(x+loopindex+1, y, z)

  • Thanks

    That's what I ended up doing. I've been using Pop to restructure arrays for so long, I hoped I could do the same for an individual element. Oh well. It works perfectly, it's just not that one line solution I'm so fond of.

  • AnD4D

    I am a bit lost. Meaning, i dont understand why you need the first number. Why the 1 in 1,5 ?

    That '1' is just a virtual number and is in fact just the index on the X-axe.

    Meaning, the array can just be 1 dimensional. No more.

    Instead of

    1,4

    2,8

    3,9

    It will be 4,8,9

    4 on the index 0 on the X-axis

    8 on the index 1 on the X-axis

    3 on the index 2 on the X-axis

    Arrays are zero based.

    If you want the second number, that number is at Array.at(1)

    Want to compare, it is just Compare at X (x=1)

    If you want to scrap the second number just Array>delete .. index = 1 ... Axis = X . The others just shift.

    If you want to insert a number so it will land on the second place ... Array>insert .. value is new number .. index = 1 .. Axis = X .. the others auto shift

    Loop trough all numbers .. just .. for each element .. X

    etc ....

    Let the array take care of that 'first' number. You dont have to. It is just virtual anyway. That is why the Array is how it is made for.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 99Instances2Go

    Sorry, that was just to represent what I wanted. Perhaps I should have used letters rather than numbers to better demonstrate.

    A,D

    B,E

    C,F

    or

    A,B

    C,D,

    E,F

    It really didn't matter what the data contained.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)