Possible Array Bug?

Discussion and feedback on Construct 2

Post » Wed Jun 14, 2017 5:37 pm

So I've been recently experimenting with arrays and I found that after setting a size limit on the array, they simply stopped working.
After toying with it a bit, I found out why:

I basically use arrays as multiple variables (Like instead of having 2 variables for each sprite's coordinates, I would use an array) and I would only use the width of the array, so when I set the size of the array I thought: "I'll use 10 positions on the width and I can set the height and depth to 0 since I won't use them"
But after I made that change, the array would not work. Later on after I tried setting the height and depth to 1, It started working again.

So my question is, if the arrays are 0-based, why do I need to set it's value to at least 1?
Is this a bug, or am I missing something?


P.S. I'm sorry for any spelling mistakes, I wrote this on a pc with no spell checking =D
ImageImageImageImage
B
30
S
9
G
7
Posts: 245
Reputation: 5,602

Post » Wed Jun 14, 2017 7:38 pm

It's working as intended. When you set the size you need to at least use 1 for each of the dimensions. If it helps the number of values in the array can be calculated with width*height*depth, so if any are 0 then no values can be stored.
B
92
S
32
G
109
Posts: 5,291
Reputation: 70,993

Post » Wed Jun 14, 2017 7:50 pm

R0J0hound wrote:It's working as intended. When you set the size you need to at least use 1 for each of the dimensions. If it helps the number of values in the array can be calculated with width*height*depth, so if any are 0 then no values can be stored.

I see... Thanks for the explication!
B
30
S
9
G
7
Posts: 245
Reputation: 5,602

Post » Wed Jun 14, 2017 10:03 pm

In addition to R0J0hound's explanation, it personally helps me to visualise it like a 3-dimensional cube. Even though Depth is not 'used', it still needs a size to be there in order to store Height and Width. A single 'slot' in the array requires a 'location' in the cube, which must have at least 3 dimensions.

(I think this is because an Array in C2 is intrinsically a 3-dimensional array -- unlike in other programming languages -- so it follows this concept.)
B
41
S
12
G
1
Posts: 69
Reputation: 2,957

Post » Wed Jun 14, 2017 10:50 pm

Yet, it is very legit to set an array to size zero on the X-axis, and minimum 1 on the other two.

The purpose is this.
Add a new index (on X) based on a loop, so you end up with an array with a width = a loopindex. Not one less, not one index more.
So .....

Some group
Some condition
____ Array > action > Set size ... (0,1,1)
Some loop
____ Array > action > Push (front) < makes a new X-axis element on X = zero
____ Array > Set at XYZ ... <--- With X = ZERO to fill values on Y or Z .. example = at (0,1)

or

Some group
Some condition
____ Array > action > Set size ... (0,1,1)
Some loop
____ Array > action > Push (back) < makes a new X-axis element on the end of the X-axis
____ Array > Set at XYZ ... <--- With X = Array.width - 1 ... example = at (Array.width - 1,1)
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Jun 14, 2017 11:07 pm

@ faulknermano

I used to picture arrays that way, but it got me into problems.
Now i picture them as threes.

Each X is another branch on the trunk.
Each Y is another branch on the X.
Each Z is another branch on the Y.

Image

Or.

Each Z is a branch on a Y, that is itself a branch on the X, that is itself a branch on the trunk.

Now i always know where my values are.

Where = the index.
Value = the stored value on that index.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Jun 15, 2017 6:36 am

@faulknermano
No I got that, just thought it was a bit weird that the first cube wasn't cube 0...

@99Instances2Go
That's an interesting way of looking at arrays, thanks for sharing!
B
30
S
9
G
7
Posts: 245
Reputation: 5,602


Return to Construct 2 General

Who is online

Users browsing this forum: bounty, jook00 and 22 guests