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

For questions about using Classic.

Post » Sat Feb 13, 2010 9:13 pm

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.
Follow me on Twitter @evgLabs
B
33
S
14
G
4
Posts: 251
Reputation: 4,049

Post » Sat Feb 13, 2010 9:23 pm

Any more details? Are the variables random? Or counting up steadily until reaching a limit?
B
9
S
2
G
4
Posts: 346
Reputation: 2,726

Post » Sat Feb 13, 2010 10:21 pm

[code:615x1f1t]
+ 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.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Sun Feb 14, 2010 1:55 am

Or, taking Deadeye's example further:

[code:28sb9ktb]
+ 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.
B
2
S
2
G
3
Posts: 406
Reputation: 2,062


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests