Stop negative numbers in numeric variable

Feb 08, 2020

I've set up a numeric variable to countdown from 9 - 0 to represent the number of drag items to use in a drag and drop.  

Each drag item has a trigger to say subtract 1 from variable when user drops item.

There is a trigger to return variable to 9 if user gets try again layer.

The issue I am having is if the user changes their mind before they hit the submit button and drags to another drop item i then get negative numbers if already at 0 or subtracts too many if not all cards have moved. Is there a way to stop double counting?

4 Replies
Walt Hamilton

Actually, the problem is not double counting, it is double subtracting. you may not think that is a big distinction, but it really is, as you found out. It's really tough to know when to subtract, or not, but if you count, it is always accurate.

It works like this: When an object is dropped, count how many are actually dropped, instead of adding or subtracting.

Here is a sample that will illustrate. It counts the number of correct dropped targets when the submit button is clicked.

It uses variables to determine if the box is dropped correctly or not. If the box is dropped on a correct target (dark circle), its variable is set to true. If it is dragged off a target (crosses the light circle), its variable is set to false. To use it, I would set the light circle to have a transparency of 100%.

It may not be exactly what you are trying to do, but clicking the submit button always finds the correct number of targets dropped and places it into totalCorrect.