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

Just started using Construct 2? Post your questions here

Post » Sat Jul 29, 2017 10:30 pm

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...?
Last edited by mimiha on Sun Jul 30, 2017 1:24 am, edited 1 time in total.
B
17
S
3
G
1
Posts: 13
Reputation: 1,370

Post » Sat Jul 29, 2017 11:32 pm

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.
Last edited by R0J0hound on Sat Jul 29, 2017 11:35 pm, edited 1 time in total.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Sat Jul 29, 2017 11:33 pm

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'.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sun Jul 30, 2017 1:24 am

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!!
B
17
S
3
G
1
Posts: 13
Reputation: 1,370

Post » Sun Jul 30, 2017 12:53 pm

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'.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests