# How do I Check an Array?

Get help using Construct 2

### » Sat Nov 19, 2016 1:53 pm

I have an inventory system set-up with an Array where X = Item Amount & Y = Item ID.

There is 50x and 2y.

The problem is I don't want to have to make 50 events to check each and every slot in the Array on the Y axis to just find one id.

I know currently I could do it like

inventory compare at X Y (1,1) = 1 DO such and such
inventory compare at X Y (1,2) = 1 DO such and such

But that is extremely tedious does anyone know of a better way to find IDs inside an array?
B
25
S
9
Posts: 116
Reputation: 2,797

### » Sat Nov 19, 2016 1:57 pm

'Contains value' is a check throughout the whole array that a specific item exists, is that what you want?
B
49
S
20
G
89
Posts: 2,341
Reputation: 52,693

### » Sat Nov 19, 2016 2:01 pm

plinkie wrote:'Contains value' is a check throughout the whole array that a specific item exists, is that what you want?

If I used that how would it know the difference between an ID of 2 and an item of 2?
B
25
S
9
Posts: 116
Reputation: 2,797

### » Sat Nov 19, 2016 2:07 pm

It wouldn't, I didn't realise you were filling it with numbers. You can probably limit it to the Y axis somehow, I'll take a look. There's a for each element check as well where you might be able to compare at Y only.
B
49
S
20
G
89
Posts: 2,341
Reputation: 52,693

### » Sat Nov 19, 2016 2:14 pm

Yeah use a for loop for 0-50. Then compare at xy, where x is 0 and y is loopindex. It'll run through all Y and check for whatever value you put in. Or just alter that functionality to do whatever values you want with a loop, I guess for yours you run the loopindex on x and compare against y=1 or y=2.
B
49
S
20
G
89
Posts: 2,341
Reputation: 52,693

### » Sat Nov 19, 2016 2:24 pm

Alright cool I'll give it a try
B
25
S
9
Posts: 116
Reputation: 2,797

### » Sat Nov 19, 2016 2:26 pm

plinkie wrote:Yeah use a for loop for 0-50. Then compare at xy, where x is 0 and y is loopindex. It'll run through all Y and check for whatever value you put in. Or just alter that functionality to do whatever values you want with a loop, I guess for yours you run the loopindex on x and compare against y=1 or y=2.

could you show an example of how you did it?
B
25
S
9
Posts: 116
Reputation: 2,797

### » Sat Nov 19, 2016 2:31 pm

I set a value of 16 at x=47, y=2. Loop runs through all x at y=2 to find it.
https://dl.dropboxusercontent.com/u/495 ... check.capx
B
49
S
20
G
89
Posts: 2,341
Reputation: 52,693

### » Sat Nov 19, 2016 2:34 pm

plinkie wrote:I set a value of 16 at x=47, y=2. Loop runs through all x at y=2 to find it.
https://dl.dropboxusercontent.com/u/495 ... check.capx

Alright thank you
B
25
S
9
Posts: 116
Reputation: 2,797

### » Sat Nov 19, 2016 2:40 pm

Wow man, That has saved me so much time! Thank you so much bro!
B
25
S
9
Posts: 116
Reputation: 2,797

Next