When do system variables update?

variables
locationmode

#1

When do variables, e.g. $locationMode, change states? I have a piston that uses “Set location mode”, and then at the bottom of the piston changes the piston state to a string containing $locationMode (the idea is for the piston to report on the dashboard via the piston state message what it changed the location mode to and when). The mode icon at the top of the dashboard properly reflects the new mode, but the piston state message always shows the mode that was set before the piston ran.

It seems like the system variables, or at least $locationMode anyway, are set at the beginning of the piston’s execution and do not change even if the piston executes a task that should change them.

Is that the case?