# How do I count specific values in an array?

0 Favourites
• 5 posts
• I have a 2 dimensional array with a width of 4 and a height of 438. (If I'm using those terms correctly, and I believe I am.) Imagine it looks something like this:

[100,text,text,0]

[124,text,text,1]

[198,text,text,2]

[113,text,text,3]

[256,text,text,4]

...

I have two variables called "over_100" and "under_100". How do I iterate through my array, row by row, and increment those two variables based on the data in the first column? (100, 124, 198, etc.)

Another quick question: I've written a lot of stuff in Excel VBA over the years. Do C2's arrays work the same way? To iterate through a spreadsheet I use: "cells(row,col)" but I think that makes the height "x" and the width "y" which is backwards compared to C2, right?

• ## Try Construct 3

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

Construct 3 users don't see these ads
• Hi,

so you just want to count the elements with over100 (under100) in the first row?

What about exactly 100 or 0.

I have made a small example, you can find it here:

I hope it helps.

• Thanks a lot dsminor. I really appreciate you taking the time to do that for me!

• To compare the values in a single column you can use "For" loop..

column=0

example.capx

.......................................................

Array WIDTH=2 ; HEIGHT=4

• I'm clearly struggling to understand C2's arrays. Here's how MY array looks in the debugger:

``````0        [119,Pour,For,354]
1        [125,Bonjour,Hello,128]
2        [133,Comment,How,45]
..
439      [450,Vingt,Twenty,235]
[/code:1v028imz]

Seems really straightforward.  There are 440 "rows" and each one I'm treating like a record.  The first column is a score, the second is a French word, the third is the English equivalent, and the last is my index.  Every 5 cards or so I sort everything by the score column.  That's all working great.

But the C2 debugger reports an array WIDTH of 439 and a HEIGHT of 4.  So I guess I just have my vertices mixed up, right?

In any event, I was able to get this working.  Thanks again for the help!``````