How do I creae 4D Array (and deeper)?

0 favourites
  • 10 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Is there anyway to create an array object with more than 3 Dimensions? In the past I've simply linked multiple arrays together by IDs when I need more but with my current project that isn't possible due to the scale.

    I was considering writing a custom plugin for "unlocked" arrays where you can have as many dimensions as you like, but that seems like a pain in the $$ so I wanted to know if a) someone already has done that or b) theres a simpler "native" way that I'm missing?

  • You can store UIDs of sub-arrays, or sub-arrays as JSON strings, or simply comma-separated strings of values. I can't think of any other option.

    Actually, if you have multiple instances of 3D array, you can think of them as of one 4D array :)

  • Yeah that's what I've done in the past. Simply had multiple arrays and on the Z-axis of one stored the UID of the next one.

    But that isn't dynamic which is what I need. I don't know how deep it will go so was hoping for a way to just continually chain on more and more as and when needed. Might look at JSON Objects but then that'll be a lot of parsing as I try to find the end to add more.

    Might just write an unlocked array plugin which allows you to just add more depth to arrays as you need.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Do you literally want a n-dimensional array, or do you want an array that contains values or other arrays?

    For an actual n-dimensional array you could use a 1d array to do it. The size would be width*height*depth*... and accessing would be:

    For 2d

    Y*width+x

    3D:

    (Z*height+y)*width+x

    4d:

    ((W*depth+z)*height+y)*width+x

    And so on

    You’d probably wrap that in a function and you could make it resizeable with a bunch of inserts/deletes to move stuff around.

    For a 4d array you could also just use multiple instances of a 3D array and access it with array(x).at(y,z,w)

    You’ll have to deal with new instance picking if you end up creating more instances, not to mention you’d be limited to adding to the end of one dimension.

    The idea may be extendable for more dimensions. I like the uid idea too, but you’ll have to be more deliberate about setting it up.

    Now the issue with n-dimetional arrays is the amount of memory really blows up the more dimensions you add. Which is why I asked if what you want is arrays that contain values or other arrays, each with their own size. Kind of like a file tree.

    Anyways I’d imagine json might work for that. I don’t know if you can use it as a dynamic data structure or just to access the data since I haven’t used it.

    You could also use a normal array to do the dynamic tree structure. Basically you’d store values in pairs: a type and a value. The type would be either be “value” or “array”, and the value would be anything or the uid of another array. You’d then just use a function to do the reading, writing and any sort of extending/resizing. I guess the main aggravation here are errors. Your lookup should be simple as function.call(“at”, arrayid, x, y, z, w) which would access access each parameter as an array index. The trouble is if it tries to access a value as an array. There you could put put an error, which may be hard to hunt down in events, or just output 0 like normal events do out of range.

    If you ended up making a plugin you can detect where in the event sheet the calls are done, so that may help. There may. E a way to do it with the browser execjs action as well.

    Anyways a few other ideas for you. Personally I’d go the event based route. It’s easier to maintain and update.

  • Thanks R0J0hound for your (always) helpful input! I managed to spend a bit of time and re-structure my underlying mechanics to only require 1 extra dimension which I'm just using a collection with 2 arrays in it. But I think as a side project I might fiddle with creating some Event based functions for both the n-dimensional array and the dynamic type/value lookup as well. Simply as an experiment

  • Heh, don't forget Canvas, you get r,g,b, and a at xy.

    With a few caveats...

  • Heh, don't forget Canvas, you get r,g,b, and a at xy.

    Isn't this only 3D array? Values r,g,b,a are all on one axis.

  • Im not sure about C3, but you R0j0's plug allows sampling r g and b independently, as well as the alpha, of course it would be the same for all three.

    Its limited to 255 for the channels, and 0 to 1 for alpha, but then again its "millions of colors" as a composite.

    Getting pixel data from henky gpu's is another argument all together.

  • newt This is still only a 3D array :)

    x is width, y is height and r,g,b,a are all on the depth axis.

  • Depends on how you look at it.

    Technically it's still just 2d.

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