Forum Discussion
Help creating a bar which counts found objects using variables/states
The danger of adding one to the count when an object is clicked, is that another one will be added if the same object is clicked again.
It’s safer to count all the selected objects when one of them is selected. It works like this:
Create a layer (Count) with nothing on it, that doesn’t hide other layers, and hides itself when its timeline ends. Set the timeline to .25 sec. Set all the triggers to fire when the timeline on the layer starts and put them in this order:
Set hoaObjects to 0
Add 1 to hoaObjects if state of Object1 = Selected, etc. for each Object. (each object needs a selected state, but it doesn’t have to look different than Normal if your don’t need a visual indication of which ones are chosen.
On the base, set these triggers:
Show layer Count when user clicks Object 1, etc for all objects.
Then use Math’s trigger to change the progressBar.
This way, a second click on an object deselects it. If you want a once-selected, always-selected action, use Visited state instead of Selected for the objects.