Hundreds of features to explore
Games made in Construct
Your questions answered
Popular & trusted by schools and Universities world-wide
Construct 3 runs in the browser & works offline
Students do not need accounts with us
Our educational partners
Free education resources to use in the classroom
World class complete documentation
Official and community submitted guides
Learn and share with other game developers
Upload and play games from the Construct community
Game development stories & opinions
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?
Develop games in your browser. Powerful, performant & highly capable.
-> 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
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.
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.