Getting the MAX value of a family numeric instance

Get help using Construct 2

Post » Thu Oct 31, 2013 7:10 am

Hi,

I have a family with a numeric instance variable.
I'd like to get the max value of this variable from all family items.

Is there a way to do that?

Thanks
B
11
S
2
Posts: 40
Reputation: 811

Post » Thu Oct 31, 2013 7:21 am

local variable: maxValue=0

for each family instance
-set maxValue to max(maxValue,family.instanceVariable)

something like this.
B
17
S
8
G
4
Posts: 93
Reputation: 3,190

Post » Thu Oct 31, 2013 9:53 am

You mean that on layout start I should loop through all family instance and use the max function?

That would work I guess (I'll give it a try asap)

SO no function like Max but that would deal with families instance variable right away?

Thx for the quick answer
B
11
S
2
Posts: 40
Reputation: 811

Post » Thu Oct 31, 2013 2:04 pm

Another way to do this is to use For Each (ordered), descending, and use Stop loop to stop at the first value.
ImageImageImage
B
71
S
21
G
229
Posts: 3,687
Reputation: 128,338

Post » Thu Oct 31, 2013 2:11 pm

@blackhornet Does stop loop not just skips the current loop ?

Actually I make every time:

locale var break = 0
+ for each ordered by...
+ break = 0
- do something
- break = 1Darklinki2013-10-31 14:15:27
B
15
S
6
G
6
Posts: 512
Reputation: 5,555

Post » Thu Oct 31, 2013 2:26 pm

@Darklinki

ForEachDescending.capx

'Stop loop' stops the 'For each' from progressing, so if you do it immediately, you stop on the first one, which with 'descending', will be the highest value.
ImageImageImage
B
71
S
21
G
229
Posts: 3,687
Reputation: 128,338

Post » Thu Oct 31, 2013 2:33 pm

@blackhornet

thanks good to know
B
15
S
6
G
6
Posts: 512
Reputation: 5,555

Post » Sat Nov 02, 2013 12:57 pm

thx everybody
B
11
S
2
Posts: 40
Reputation: 811

Post » Sat Nov 02, 2013 6:10 pm

You could use max(Sprite.xz,Sprite2.xz,Sprite3.xz)
But obviously you have to list each object.

Or you could use the "Pick instance with highest/ lowest instance variable" condition.
Image ImageImage
B
168
S
50
G
169
Posts: 8,281
Reputation: 108,191

Post » Sun Nov 03, 2013 6:19 am

Ok I'll test that as well.

Good to have several ways to do it.

Thx
B
11
S
2
Posts: 40
Reputation: 811

Next

Return to How do I....?

Who is online

Users browsing this forum: JoyfulDreamer, StillSarah and 19 guests