How do I Check an Array?

Get help using Construct 2

Post » 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
23
S
8
Posts: 115
Reputation: 2,640

Post » 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
45
S
15
G
73
Posts: 2,019
Reputation: 43,420

Post » 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
23
S
8
Posts: 115
Reputation: 2,640

Post » 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
45
S
15
G
73
Posts: 2,019
Reputation: 43,420

Post » 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
45
S
15
G
73
Posts: 2,019
Reputation: 43,420

Post » Sat Nov 19, 2016 2:24 pm

Alright cool I'll give it a try
B
23
S
8
Posts: 115
Reputation: 2,640

Post » 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
23
S
8
Posts: 115
Reputation: 2,640

Post » 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
45
S
15
G
73
Posts: 2,019
Reputation: 43,420

Post » 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
23
S
8
Posts: 115
Reputation: 2,640

Post » Sat Nov 19, 2016 2:40 pm

Wow man, That has saved me so much time! Thank you so much bro!
B
23
S
8
Posts: 115
Reputation: 2,640

Next

Return to How do I....?

Who is online

Users browsing this forum: Darth Crusher, NN81, plinkie, TsubaRu and 10 guests