To add to @theophile excellent answer. You can share these variable objects across different macros like
[delayed_gcode i_depend_on_test]
gcode:
{% set vars = printer["gcode_macro TEST"] %}
M117 {vars.my_shared_variable}
[gcode_macro TEST]
variable_my_shared_variable: -1
gcode:
SET_GCODE_VARIABLE MACRO=TEST VARIABLE=my_shared_variable VALUE={params.MY_SHARED_VARIABLE|default(10)}
UPDATE_DELAYED_GCODE ID=i_depend_on_test DURATION=0.01
So, once TEST MY_SHARED_VARIABLE=100
is executed, then i_depend_on_test
is called and can access the variable’s content, which then is 100.