how to pick an instance by higher value?

Get help using Construct 2

Post » Thu Sep 27, 2012 10:14 am

Say I have 4 instances of the same object constantly setting a random value, but I want to know which one got the highest and do something with that one.

Like every x seconds, pick instance with highest value and set scale to 2 or something.

How would one go about doing this?


Edit: I though that maybe i can do something like "when instance 1 value is greater than value of 2,3,4,5,6,7 set scale to 2" and then do the same with every other instance. but seems kind of impractical... maybe arrays?
Although I'm looking for a way to do a modular event that would pick the highest value of a varying number of instances.Sargas2012-09-27 10:18:52
B
42
S
11
G
5
Posts: 446
Reputation: 6,417

Post » Thu Sep 27, 2012 12:35 pm

One way to do it would be to add an instance variable to the object (Can't think of a good name so I just used 'B') and an event with the system condition:

"for each object by order of Object.RandomValue ascending"
             --> set object.B to loopindex

This will number each object.B by the order in which it was picked. going from 0,1,2,3 .. etc

Then in a separate event, to pick the highest, you can do

Object.loopID = object.count-1
      -->set scale to... etc

the -1 is necessary because the 'loopindex' expression is 0 based (0,1,2,3..), but the 'count' expression isn't (1,2,3,4..)
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Thu Sep 27, 2012 2:13 pm

I think I getit. So once the value is set, the loopindex will sort them in order and then I can just pick one (first or last one in my case).

I'll give it a try and see if this is what i'm thinking about.

Thanks Keepee ^^
B
42
S
11
G
5
Posts: 446
Reputation: 6,417

Post » Thu Sep 27, 2012 5:45 pm

[code]
+System: For each Object order by Object.value descending
   -> Object: Set scale to 2
   -> System: Stop loop
[/code]
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,000

Post » Thu Sep 27, 2012 7:19 pm

@ramones once again you prove to be the man =)

That's exactly what I was looking for :D
B
42
S
11
G
5
Posts: 446
Reputation: 6,417

Post » Thu Sep 27, 2012 10:14 pm

@ramones, nice..wish I thought of that.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683


Return to How do I....?

Who is online

Users browsing this forum: bluemonkey, MarkThomas and 22 guests