# Macro. Strange returned values in the loop

**URL:** <https://klipper.discourse.group/t/macro-strange-returned-values-in-the-loop/11804>\
**Category:** General Discussion\
**Created:** [November 23, 2023, 12:36pm UTC](https://klipper.discourse.group/t/macro-strange-returned-values-in-the-loop/11804 "2023-11-23T12:36:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![annocka99](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@annocka99](https://klipper.discourse.group/u/annocka99)\
**Post date:** [November 23, 2023, 12:36pm UTC](https://klipper.discourse.group/t/macro-strange-returned-values-in-the-loop/11804/1 "2023-11-23T12:36:17Z")

</div>

### Basic Information:

Printer Model: kp3s  
 MCU / Printerboard: kp3s  
[klippy.log](https://klipper.discourse.group/uploads/short-url/gPjbZ3pbI5b2WX61w9ma4idkLxl.log) (6.2 MB)

When i request values from status reference object in the loop it always returned the same value even if the value was changed.  
That is the simple example of the issue.

[gcode\_macro test2]  
gcode:  
M140 S40  
{% for i in range (10) %}  
RESPOND TYPE=echo MSG=‘{printer.heater\_bed.temperature}’  
G4 P2000 # Wait for one second  
{% endfor %}  
M140 S0

---

<div class="post-metadata">

**Author:** ![Sineos](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/sineos/32/18_2.png) [@Sineos](https://klipper.discourse.group/u/Sineos)\
**Post date:** [November 23, 2023, 1:03pm UTC](https://klipper.discourse.group/t/macro-strange-returned-values-in-the-loop/11804/2 "2023-11-23T13:03:45Z")

</div>

See

> [@Help with Macro: SET\_GCODE\_VARIABLE doesnt set my variable](https://klipper.discourse.group/t/help-with-macro-set-gcode-variable-doesnt-set-my-variable/11014/10):
>
> That’s because macros are evaluated before they are run. All the variables are “translated” before the macro is executed so if the macro itself changes the value of a variable, that change won’t be reflected during the same execution of the macro. To work around this, create a second macro called something like TEST\_RESPOND, have that macro do the RESPOND TYPE=error MSG=‘{test}’ line, and call TEST\_RESPOND at the end of TEST. Keep in mind that TEST\_RESPOND will need to lookup the value of the te…

and following posts for an explanation.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/klipper/original/1X/64419bf2aac6639e6ef5cef200dcd456b0a01ac3.png) [@system](https://klipper.discourse.group/u/system)\
**Post date:** [December 23, 2023, 11:04pm UTC](https://klipper.discourse.group/t/macro-strange-returned-values-in-the-loop/11804/3 "2023-12-23T23:04:13Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
