Get the correct last_position in GCODE Script

I want to use a custom GCODE Script to Auto-z-calibration on a dual x-carriage setup.
I wrote the following code:

G1 F40000 Z5
G30 X200 Y200
{% set z0 = last_position.z %}
M117 z0 {{z0}}
G1 F40000 Z5
G1 F40000 X-50
G30 X200 Y200
{% set z1 = last_position.z %}
M117 z1 {{z1}}
G1 F40000 Z5
G1 F40000 X500
G1 F40000 X-50 Y400
{% set delta = z0-z1 %}
M117 "Delta: {{delta}}"
M218 T1 Z{{delta}}

The idea was to make a single Z-Probe on each Extruder (Toolhead) and then calculate The Z-Offset of both Nozzles. I need to say, that I have preasure sensitive print bed.
I used a M114 to get the position an then I wanted to read it from last_position.
How ever I tried it, The value comming from last_position is something completly different and does not change during both readings. As a test I used 2 different X-positions and read last_position.x) The result was that I got with M117 the last X-position of G29.

What am I doing wrong? Where is the mistake. I'm thankfull for every hint.


The second call to M114 appears to be commented-out, btw.