In most application variables defined with global definition are evaluated before any variables defined with the standard equal sign.
Your program may work if all variables and functions are defined with global definition.However, I do not see how the global definition in this case provides any improvement or advantage compare with the regular equal sign definition.