How do I extract data from 3D array

Get help using Construct 2

Post » Sat Jul 09, 2016 11:37 am

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
B
13
S
6
Posts: 130
Reputation: 1,553

Post » Sat Jul 09, 2016 12:50 pm

maybe try for "i" from 0 to Array.Width instead for each X element
B
12
S
3
Posts: 211
Reputation: 1,477

Post » Sat Jul 09, 2016 1:50 pm

Fireche wrote: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!
B
13
S
6
Posts: 130
Reputation: 1,553

Post » Sat Jul 09, 2016 2:25 pm

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.
ImageImageImage
B
71
S
21
G
231
Posts: 3,688
Reputation: 129,352

Post » Sat Jul 09, 2016 2:36 pm

blackhornet wrote: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?
B
13
S
6
Posts: 130
Reputation: 1,553

Post » Sat Jul 09, 2016 3:05 pm

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 ...
ImageImageImage
B
71
S
21
G
231
Posts: 3,688
Reputation: 129,352

Post » Sat Jul 09, 2016 3:25 pm

blackhornet wrote: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! :)
B
13
S
6
Posts: 130
Reputation: 1,553

Post » Sat Jul 09, 2016 3:30 pm

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.
ImageImageImage
B
71
S
21
G
231
Posts: 3,688
Reputation: 129,352

Post » Sat Jul 09, 2016 3:39 pm

blackhornet wrote: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
B
13
S
6
Posts: 130
Reputation: 1,553

Post » Sat Jul 09, 2016 3:59 pm

blackhornet wrote: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! :)
B
13
S
6
Posts: 130
Reputation: 1,553

Next

Return to How do I....?

Who is online

Users browsing this forum: tarek2 and 19 guests