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

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

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

  • Try Construct 3

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

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