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

Get help using Construct 2

Post » 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
86
S
27
G
10
Posts: 256
Reputation: 11,365

Post » 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,370

Post » 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
86
S
27
G
10
Posts: 256
Reputation: 11,365

Post » Mon Aug 24, 2015 7:45 pm

With a function:
Image

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

Post » 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
ImageImageImage
B
71
S
21
G
230
Posts: 3,687
Reputation: 128,845

Post » 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

Post » Mon Aug 24, 2015 8:46 pm

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

Post » Mon Aug 24, 2015 9:16 pm

ramones wrote:Image

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,370

Post » Mon Aug 24, 2015 10:43 pm

@blackhornet, @Borgi

Both these solutions worked well, thanks!!!!
B
86
S
27
G
10
Posts: 256
Reputation: 11,365


Return to How do I....?

Who is online

Users browsing this forum: David181, Shenkai the ssj, Yahoo [Bot] and 22 guests