# How do I Get the Lowest Non-Zero Number with min()?

Get help using Construct 2

### » Mon Aug 24, 2015 6:31 am

So say i have these numbers : 50, 100, 40, 0, 0, 20

I want to use min(50, 100, 40, 0, 0, 20) to get the lowest number, but i don't want it to return any of the zero values. Thus the result should be 20.

Any ideas how i would achieve this in C2? In normal coding this is quite easy but i'm drawing a blank in C2.
B
101
S
35
G
12
Posts: 295
Reputation: 13,684

### » Mon Aug 24, 2015 7:46 am

The first thing it comes to my mind is using Array. It might be a bit clunky.
Here is my capx https://drive.google.com/file/d/0B_ZRhC ... sp=sharing
It's time for me to return the favor :)
B
32
S
9
G
9
Posts: 132
Reputation: 5,375

### » Mon Aug 24, 2015 6:53 pm

Thanks, I was thinking about using an Array object to do this but was wondering for some workable expression . Will give it a go.
B
101
S
35
G
12
Posts: 295
Reputation: 13,684

### » Mon Aug 24, 2015 7:45 pm

With a function:

minNonZero.capx (r212)
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,860

### » Mon Aug 24, 2015 8:01 pm

@ramones, sorry but this fails if the first parameter is zero.
edit:
@ikke2902, yours also fails if the first element is zero.

www.blackhornettechnologies.com/Constru ... e_BHT.capx
B
71
S
22
G
279
Posts: 3,838
Reputation: 153,878

### » Mon Aug 24, 2015 8:34 pm

an ugly solution:
find min in (a1,a2,a3,a4...) -> if not 0 -> YAY
else
find max, store it in aMAX
find min ( a1 = 0 ? aMAX : a1, a2 = 0 ? aMAX : a2, ... )
B
10
S
2
G
1
Posts: 51
Reputation: 761

### » Mon Aug 24, 2015 8:46 pm

B
55
S
29
G
19
Posts: 1,520
Reputation: 25,860

### » Mon Aug 24, 2015 9:16 pm

ramones wrote:

Haha it applies to me aswell. My code works if the first pop axis action has been removed. No idea why it was there :/
Though, the method from BlackHornet is more elegant
It's time for me to return the favor :)
B
32
S
9
G
9
Posts: 132
Reputation: 5,375

### » Mon Aug 24, 2015 10:43 pm

@blackhornet, @Borgi

Both these solutions worked well, thanks!!!!
B
101
S
35
G
12
Posts: 295
Reputation: 13,684