Im working on a little project that uses drivers... I have used them extensively but Im failing to find a solution for this problem. In this project I wont use scripts. Also, this is not on BGE, but on the regular viewport.
Im trying to make a driver expression on an empty0 so that it's X location is added by 1 every time some other event happens. For example, if a cube location goes from 0 to 1, add+1 to empty0 once. But this must work on runtime, 24fps.
So this is the problem: driver expressions are little pieces of code that are run every frame change, therefore every time I do something like:
"add +1 to variable1 if some other variable2==1"
it doesn't do it only once, it will check 24 times a second if the variable2==1 and will add +1 to variable1 24 times in a second. I wanted it to only add +1 one single time every time the cube goes to x==1. If I move the cube back to zero, nothing should happen, If I move the cube back to 1 again, it should add+1 to empty0 xloc one more time only, until I repeat the process
If drivers had a "While loop" to check "while variable2==1" before making the addition to variable1, it would solve the problem. But I don't think there is, and I cannot think of another way of simulating a "while" using other drivers and tricks.
The core of the problem is the fact that a driver is being run 24 times a second and I wanted to add a simple +1 to x location of an object just once every time a cube location =1.
Maybe someone here has an idea of how to solve it...
Heres a blend file as example of the problem:


0 if frame == 1 else var if frame%24 != 0 else var+1 if var1==1 else var) evaluates as the driver expression in place of your previous expression. – Leander Apr 18 '18 at 06:53abs(ob.location.x - 1) < TOLis a safer test for float equivalence. – batFINGER Apr 18 '18 at 11:02