Array size (1,1,1) = (2,1,1)?

0 favourites
  • 3 posts
From the Asset Store
220 Food Sprites in 16x16 pixel size. Perfect for items for a retro style game.
  • So I was having trouble accessing the elements of my arrays correctly, and I think I found the problem.

    Say I have an array and set its size to (1,1,1), then push a 9 to the back.

    When I tell my string object to display Array.At(0) (which should be the first and only element in an array of this size), it says "0." However, when I set it to Array.At(1), it shows "9"

    When I set the array size to (0,1,1) which, according to the manual, should be illegal, the textbox shows "9" at Array.At(0), and "0" at Array.At(1), meaning that the array has a width of 1.

    So it seems like arrays always set their x-width to one higher than you specify. Am I right, or just missing something?

  • Setting the size to 0 allows for the push action, creating an index for the newly pushed value.

    If you push a value in an array of width=1, is already = 0 and your new value will be put in index 1.

    If you push a value in an array of width=0, your new value will be put in index 0.

    Pop actions works the same, deleting/removing the specified index (back or front).

    Perhaps the manual needs an update on that specificity, pop and push actions were added after the first edit of the entry.

    Ashley, you probably have a better way to formulate the explanation and perhaps could edit the entry ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Oh okay, I thought that "size" was the max number of values the array was allowed to hold, rather than just the starting size. Thanks for clarifying.

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