0 Favourites

# Possible Array Bug?

• 7 posts
• 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

• 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.

• 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!

• 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.)

• 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)

• 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.

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.

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

Construct 3 users don't see these ads
• 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!

• 7 posts