How do I compare values and if not equals pick highest?

Just started using Construct 2? Post your questions here

Post » Wed Mar 08, 2017 6:00 pm

I need to check the values of the same variable in the 25 instances and get the instance that have the highest value if it is unique or request that the user changes the equal values. I believe I will need to use the "Sprite>Pick highest" event but I don't know how to build it.
B
4
S
2
Posts: 136
Reputation: 874

Post » Wed Mar 08, 2017 8:28 pm

I'd create a Function that fills an Array with all the values your looking at and then pick the highest value in the array.
B
71
S
41
G
24
Posts: 356
Reputation: 18,464

Post » Wed Mar 08, 2017 8:39 pm

Local variable TheHighest

Sprite>Pick highest
_____Set highest to the highest instance value
Sub ____ System > pick all
_________ Sprite > Compare instance variable =? TheHighest
_________System > compare 2 values ... Sprite.PickedCount =? 1
___________________actions run if there is only 1 TheHighest
_________Else
___________________actions run if there is more then 1 TheHighest
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Mar 09, 2017 5:36 pm

99Instances2Go wrote:Local variable TheHighest

Sprite>Pick highest
_____Set highest to the highest instance value
Sub ____ System > pick all
_________ Sprite > Compare instance variable =? TheHighest
_________System > compare 2 values ... Sprite.PickedCount =? 1
___________________actions run if there is only 1 TheHighest
_________Else
___________________actions run if there is more then 1 TheHighest



I was doing something like that but I forgot to include the "compare 2 values" condition in the same event of the two others. Thank you.
B
4
S
2
Posts: 136
Reputation: 874


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest