# How do I count specific values in an array?

Get help using Construct 2

### » Sun Feb 07, 2016 2:36 pm

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?
B
16
S
5
Posts: 106
Reputation: 1,389

### » Sun Feb 07, 2016 3:59 pm

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.
B
7
S
2
Posts: 56
Reputation: 583

### » Sun Feb 07, 2016 4:58 pm

Thanks a lot dsminor. I really appreciate you taking the time to do that for me!
B
16
S
5
Posts: 106
Reputation: 1,389

### » Sun Feb 07, 2016 5:09 pm

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

column=0

example.capx

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

Array WIDTH=2 ; HEIGHT=4
Last edited by korbaach on Sun Feb 07, 2016 11:24 pm, edited 1 time in total.
B
67
S
24
G
7
Posts: 1,519
Reputation: 11,104

### » Sun Feb 07, 2016 8:46 pm

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

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

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!
B
16
S
5
Posts: 106
Reputation: 1,389