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: 123
Reputation: 846

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
56
S
33
G
23
Posts: 334
Reputation: 16,743

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,474
Reputation: 20,912

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: 123
Reputation: 846


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests