Simple if condition not working, what am I missing
-
I wanted to use the meta-commands to adjust my babystepping for prints, however, my if statements never trigger even if they are true. So instead of testing the commands inside of a gcode over and over, I made a quick macro and get the same results. And for the life of me, I cannot figure out what I am doing wrong. Below is what I have tried.
echo move.axes[2].babystep
if move.axes[2].babystep = 0.050
echo "it worked"
echo "it didn't work"DWC echos the value from my Z axes babystep, and then echoes that the if statement was not true.
set global.offset = move.axes[2].babystep
echo global.offset
if offset = 0.050
echo "it worked"
echo "it didn't work"Again DWC echos the value in the global offset variable, which is axes 2 babystep value, but the if statement does not see the expression as true.
The only time I've gotten the above meta to work is by setting it to NOT equals, in which case the if statement evaluates as true.
7/28/2021, 11:39:54 AM M122
=== Diagnostics ===
RepRapFirmware for Duet 3 MB6HC version 3.3 (2021-06-15 21:45:47) running on Duet 3 MB6HC v0.6 or 1.0 (standalone mode) -
@psylenceo comparing floating point numbers for equality is never a good idea in programming, except in limited cases, because floating point maths is not exact. Use something like this instead:
if abs(move.axes[2].babystep - 0.050) < 0.001)