How do I extract data from 3D array

0 favourites
  • 11 posts
From the Asset Store
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • Hello everyone,

    I have a 3D array with data inside. I want to move through the array by first looking for the correct value on the X axis, then look on that values Y axis before finally extracting data on the Z axis. To try and put it another way I want to first search my array for one value, then only search the array on the Y axis of that value - so if my first value is at X3, I only want to then search for my next value on the Y associated with X3.

    I'm trying to loop through my arrays with Curvalue using this:

    array - for each X element

    array - cur value | BoxA

    array - for each XY element

    array - cur value | ItemA Sub item A text | set text to array.at(array.curX, array.curY, array.curZ+3)

    But I'm not getting anything out of the array at all. I'm sure I've managed this before, can anyone point me in the right direction?

    Thanks

  • maybe try for "i" from 0 to Array.Width instead for each X element

  • maybe try for "i" from 0 to Array.Width instead for each X element

    Hey Fireche,

    Thanks for your reply, I appreciate your suggestion. Could you explain a little more? I think I know what you mean but I'm not sure how to implement it.

    Thanks for your help!

  • You can't extract data from each dimension independently. A three dimensional array has to be indexed with an X, Y and Z index each time. Maybe provide a sample of the data in your array to make things clearer.

  • You can't extract data from each dimension independently. A three dimensional array has to be indexed with an X, Y and Z index each time. Maybe provide a sample of the data in your array to make things clearer.

    Thanks for your reply BlackHornet,

    that makes sense, but how would I then extract data on the Z when my two potential X and Y are dynamic. I'll try and explain more thoroughly:

    my data looks like this -

    Level A - Level B - Level C (x)

    Item A - Item A - Item A

    Item B - Item B - Item B

    Item C - Item C - Item C

    (Y)

    On the Z axis there are stats for each of the items.

    This whole thing is so I can populate the items with the data from the array when I spawn them.

    E.G. I spawn Item A

    I loop through the array and look what Level I am in (the item stats change on different levels). Then I want to loop through and select the correct item in the array on the Y. Then finally I want to write the items instance variables with the correct information from the array on the Z.

    Does that make sense?

  • You're thinking of storing the level and item, but that's not really the way to think of it, although there are different ways of doing it. You don't need to search for a level, your level maps to the index in X -> LevelA is X=0, LevelB is X=1... Your items map to Y, ItemA is Y=0, ItemB is Y=1. So the statistics for Level B, Item C are always (1,2,z). The array only contains the stat data. You do need to know the Y index for each item though. You could alternatively store the item ID always at Z=0, so then you could search for it in Y, and your statistics would always be from Z=1, to ...

  • You're thinking of storing the level and item, but that's not really the way to think of it, although there are different ways of doing it. You don't need to search for a level, your level maps to the index in X -> LevelA is X=0, LevelB is X=1... Your items map to Y, ItemA is Y=0, ItemB is Y=1. So the statistics for Level B, Item C are always (1,2,z). The array only contains the stat data. You do need to know the Y index for each item though. You could alternatively store the item ID always at Z=0, so then you could search for it in Y, and your statistics would always be from Z=1, to ...

    Thanks for the reply . I think I understand what you are getting at, but I still cant think how to get the data I'm after out of the array...

    Maybe its because my system is actually slightly more complex than I initially indicated, maybe I'm just being dense. The 'items' (objects on the Y) aren't actually items at all. They are simply IDs which are assigned at run time as an object is created - they how I planned on connecting the data on the Z with the object I just spawned.

    Basically I have items which I spawn in each level. I need to take information from an array and write it into those items instance variables. I'd like to just use one 3D array.

    Is there a better way of doing this?

    Thanks for your help, this is causing my a major headache!

  • Are your IDs fixed? IE: a hammer always has the same ID (let's say 0), axe is always 1... If your IDs are fixed, and can be numbers, then they are your Y index. Z is your instance variables.

  • Are your IDs fixed? IE: a hammer always has the same ID (let's say 0), axe is always 1... If your IDs are fixed, and can be numbers, then they are your Y index. Z is your instance variables.

    Yeah I think get what you are saying, but I still cant seem to get the data out of the array :S... This isn't my first time with 3D arrays either, I cant believe I'm so stumped on this.

    BlackHornet thanks for all your help so far, but would you just quickly write out what conditions/events you'd use to populate those variables?

    Seriously, thank you

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Are your IDs fixed? IE: a hammer always has the same ID (let's say 0), axe is always 1... If your IDs are fixed, and can be numbers, then they are your Y index. Z is your instance variables.

    Hi BlackHornet,

    I figured it out, I understand exactly what you were saying now - my major problem was I hadn't made the item ID's numbers.

    Thanks for all your help, it's really appreciated!

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