You could just create two such global variables; one that updates regulary and another one that is essentially a copy of the first. You create a function that creates a copy whenever necessary and you make another function that compares the two variables whenever you need them to be compared.