[Solved] How do I find an array's length?

0 favourites
  • 5 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • I thought "count" would do it but when I use Array.Count on my array, which is 50 wide but have 5 elements filled, it returns 1. (???) and "count" isn't actually documented on the manual page so I have no idea wtf it's supposed to do.

    I guess I could use Array.Width but looping through a ton of empty space seems like a waste of computing power...?

  • The count expression gives the number of that object type. It's documented in the common aces section of the manual.

    A loop checking how many are filled or a variable that you update as you fill the array are both good options. The loop is simple and the variable way while faster will be easier to mess up.

  • Common Conditions, Common Actions and Common Expressions have there own page in the manual.

    A ton of empty space is a heartless waste of computer memory.

    But, i suspect that you use 'zero' as a value, hence, they are not even 'empty'.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Oh ok, I didn't know Count was not an array-exclusive thing! I usually see "count" as array length in other languages

    I found the best way for my situation was to have a variable that updates each time I add to the array. Thank you for the solutions!!

  • Start with a (0,1,1) array. If you only need the X-axis. Push new values to it, to keep the array from 'wasting'.

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