# Which variable has the biggest value ?

Get help using Construct 2

### » Fri Jan 25, 2013 1:36 pm

Hi all.

Let's say we have apple, pear, banana, watermelon variables. And they have random values.

How can I get which one has the biggest value ? And If there are 2 or 3 varibles which have same biggest values, then learn that ?

This is a very long way if there are more than 4 varibles;

if apple > pear and apple > banana and apple > watermelon
if pear > apple etc ect.

Also if there are 2 variables which have same biggest values if condition goes bigger :(

Is there any easier way ? Thank you very much.Spider_hip2013-01-25 13:52:17
B
7
S
1
G
1
Posts: 76
Reputation: 904

### » Fri Jan 25, 2013 1:58 pm

Try something like this:

variable largest
variable largestValue

for each item
item.value > largestValue
largest = item
largestValue = item.value

Items could be a family, a sprite or whatever fits your needs :)vee412013-01-25 13:59:21
B
24
S
9
G
7
Posts: 756
Reputation: 7,322

### » Fri Jan 25, 2013 2:50 pm

Or just use the max function.

largestValue = Max(apple, pear, banana, watermelon)
B
80
S
33
G
27
Posts: 1,027
Reputation: 21,114

### » Fri Jan 25, 2013 2:56 pm

[QUOTE=Magistross] Or just use the max function.

largestValue = Max(apple, pear, banana, watermelon)[/QUOTE]

Nice, didn't know of that!
B
24
S
9
G
7
Posts: 756
Reputation: 7,322

### » Fri Jan 25, 2013 3:11 pm

@vee41
thank you very much. I'll try that too.

[QUOTE=Magistross] Or just use the max function.

largestValue = Max(apple, pear, banana, watermelon)[/QUOTE]

Wow I didn't know this either.

Well what if there are 2 variables which have same max values then what will be the result ?

Thank you
B
7
S
1
G
1
Posts: 76
Reputation: 904