I created a piston just to test whether I can successfully record a 'last activity' time on the even runs and report that last activity time on the odd run. I intend on using this function in other pistons.
However, I am very confused by what seems to be happening when I hit the test button. Instead of simply recording the last activity time or reporting it, the piston starts looping between both the cases. I initially tried using if statements and incrementing a run count variable by 1. And the variable kept increasing constantly.
Next I tried it with a switch/case statement and it is still looping through both conditions constantly.
How can I fix this so the code only runs when I hit test and stops after meeting only one of the conditions? And in the next 'test' run goes through the alternate condition and stops.
Thanks for the tips! I had one more question about the variable being local, will its value from initial run persist the next time it runs? The only reason I made it global was I worried that a local variable will start with 0 each time the piston runs.
Local variables can be manipulated within your piston and will maintain any changes made during execution. But if you initialize the variable to a specific value in the Define section, then that value will be assigned to your variable each time the piston executes.