0 Favourites

how to pick an instance by higher value?

  • 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.

  • 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..)

  • 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 ^^

  • +System: For each [b]Object[/b] order by [i]Object.value[/i] descending
       -> Object: Set scale to 2
       -> System: Stop loop
    
  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • ramones once again you prove to be the man =)

    That's exactly what I was looking for :D

  • ramones, nice..wish I thought of that.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
0 Favourites
[Plugin] instance bank2
85 18,379
rexrainbow's avatar
rexrainbow
Unread hot topic
38 3,971
STARTECHSTUDIOS's avatar
STARTECHSTUDIOS
Unread hot topic
0 Favourites
Pick All / Create Bug
56 1,829
Prominent's avatar
Prominent