It's correct and expected behaviour that a local variable will reset to it's initial value each tick. If you need the value to persist you probably want to make the variable static. See the manual entry for variables.
Alternatively, you could make the variable a global, but that's not something you should do unless your design really calls for it.