Hello, I have an object with a hover / selected state. I've used auto states to select / deselect when I click on an object.
I want to increment a variable when I click on this object to put it in the selected state, and to decrement it when I put it back to the normal state.
My triggers so far :
Trigger #1 : increment the counter variable by 1 when I click on the object, if the state = selected
Trigger #2 : decrement the counter variable by 1 when I click on the object, if the state = normal
For it to increment, it seems that I have to use the target (resultant) state of the click, not the initial state ... but sadly the decrementation does not work at all.
Alright, although I'd love to see the reason why I cannot decrease the counter when the click returns the object to its normal state, I have found a quicker way to do it, by using the else option :
What : Increase the counter variable by one
When : User clicks on object
Condition : if (resultant) state is selected
Else : Decrease the counter variable by one
This creates a counter of how many objects are selected. Maybe there's a quicker way to count objects based on their states ? PLS tell me.
However, neither solution would not work if you had more than one button on a slide. To track how many objects are selected you would have to use two triggers for each button. Check the attached video.
Hello Phil and Nedim, thank you both for your great answers.
To give you more details on what I was trying to do, I had a thermometer that had to go up and down depending on how many zones of a map were selected. I had it update on variable change, and the variable was changing based on the Select / Deselect states when the users clicks. It works great ... but needs quite some triggers !!
@Nedim : that's the solution I've gone for, more or less. Thanks !
@Phil Thanks for the precision. I didn't try to use the "not equal to" test, that could have saved the day ;) ... But your trick of a "calculator layer" is a very useful one, that will definitely come in handy in a next project. I think it might help getting the trigger count a bit down, and help with future maintenance (easier logic to understand for colleagues !!!).
Phil, of course, is correct. Incrementing and decrementing variables is always risky. It’s more reliable to count every time you need a change. Using a layer allows you to create one set of variables that will work for all your buttons. Everything else, do as Phil says.
I would change Nedim’s suggestion to do your changes when Button 1 is clicked, rather than relying on when the state changes to selected. Detecting state changes is not always reliable.
6 Replies
Alright, although I'd love to see the reason why I cannot decrease the counter when the click returns the object to its normal state, I have found a quicker way to do it, by using the else option :
What : Increase the counter variable by one
When : User clicks on object
Condition : if (resultant) state is selected
Else : Decrease the counter variable by one
This creates a counter of how many objects are selected. Maybe there's a quicker way to count objects based on their states ? PLS tell me.
Selected reacts as a subset of normal. You can try is not selected.
Personally I would have a layer show each time they click and have the layer count the selected states and then close.
You may use this trigger based on a button state.
However, neither solution would not work if you had more than one button on a slide. To track how many objects are selected you would have to use two triggers for each button. Check the attached video.
Simpler to show a layer, set trigger to reset counter to 0 then add one for every selected state then hide layer
Hello Phil and Nedim, thank you both for your great answers.
To give you more details on what I was trying to do, I had a thermometer that had to go up and down depending on how many zones of a map were selected. I had it update on variable change, and the variable was changing based on the Select / Deselect states when the users clicks. It works great ... but needs quite some triggers !!
@Nedim : that's the solution I've gone for, more or less. Thanks !
@Phil Thanks for the precision. I didn't try to use the "not equal to" test, that could have saved the day ;) ... But your trick of a "calculator layer" is a very useful one, that will definitely come in handy in a next project. I think it might help getting the trigger count a bit down, and help with future maintenance (easier logic to understand for colleagues !!!).
Thanks a lot,
Phil, of course, is correct. Incrementing and decrementing variables is always risky. It’s more reliable to count every time you need a change. Using a layer allows you to create one set of variables that will work for all your buttons. Everything else, do as Phil says.
I would change Nedim’s suggestion to do your changes when Button 1 is clicked, rather than relying on when the state changes to selected. Detecting state changes is not always reliable.