How to tell if all objects' variable is the same value

This forum is currently in read-only mode.
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I need to trigger an action when all instances of the same object have the same value for a variable. And I can't figure this out.

    How do I do what I wanna do? I wish I knew.

  • Any more details? Are the variables random? Or counting up steadily until reaching a limit?

  • + Always
        -> Set global('average') to 0
    
    + For each object
        -> Add object.Value('variable') to global('average')
    
    + Compare:  global('average') / yourNumber is equal to number of objects
        -> Do your thing
    [/code:615x1f1t]
    
    Maybe?  If not then it might help to have more information.
    
    By the way, this will only work reliably if there is a maximum value for your object's variables, and you are checking if the numbers are all at max.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Or, taking Deadeye's example further:

    + Start of comparison
        -> Set global('sample') to Random Object.value('variable')
        -> Set global('TestFlag') to 0
    
    + For each object
        -> Compare object.Value('variable') to global('sample')
            -> If Variable<>Sample then set global('TestFlag') to 1
    
    + Compare:  global('TestFlag')
        -> If 0 do you thing![/code:28sb9ktb]
    
    In short, you set a flag to 0, choose one of the objects at random and take that value as a sample, then loop through all objects checking the contents against the sample each time, setting the flag to 1 if the compare on any of the objects fails.
    
    This way, the only way the flag will still be 0 after the looped compare has taken place is if ALL the variables of the object are the same.
    
    Krush.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)