Which variable has the biggest value ?

Get help using Construct 2

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

Post » 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
8
G
7
Posts: 756
Reputation: 7,192

Post » Fri Jan 25, 2013 2:50 pm

Or just use the max function.

largestValue = Max(apple, pear, banana, watermelon)
B
45
S
16
G
18
Posts: 845
Reputation: 13,673

Post » 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
8
G
7
Posts: 756
Reputation: 7,192

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


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 4 guests