How to check if variable is float or int
-
Hi,
I need some help
Is there a way in meta-commands to check if the curent value of a variable is int or float? my code is like thatwhile iterations <25000 M106 S1.0 G4 P300 if sensors.endstops[0].triggered = false set var.pp1 = {var.pp1+1} ; G4 P30 set var.Aa = {var.Aa+1} ***if var.Aa = 3125 || 6250 || 9375 || 12500 || 15625 || 18750 || 21875 || 25000*** set var.StartT = {state.time - var.StartT} echo state.time echo var.Aa echo >>"sys/counts" "---------------------------------------------" echo >>"sys/counts" state.time echo >>"sys/counts" var.StartT , "Obshto vreme /secundi" set var.StartT = {var.StartT/var.Aa}
I need to echo the time on every 3125 cylces . In C I can check whenever a variable is INT
i.e IF var.Aa is Integer and Echo current status on screen/file
is there a way to do this in meta comands -
@martin7404 how about this:
if mod(var.Aa, 3125) = 0 ...
-
@dc42 thank you I will try.
In the documentation there is only mod command with no explanation and i still do not understand how it works.
I will try it tommorrow thank you -
mod(x,y)
will return the remainder of division.so
mod(5,2)
would return 1
mod (17,3)
would return 2
mod(6,3)
would return 0Therefore
if mod(var.Aa, 3125) = 0
can only return true if var.Aa is a multiple of 3125
In all other cases there will be a remaining decimal fraction.In your code, it will never report 25000 as you have set the loop to < 25000
You would need to change it to <=
Also your indentation seems off where you set the two variables, but that may be a copy/paste thing. -
@owend thank you
-
In the end both versions with boolean or , and with mod comand did not work. Both program stops on the second itteration of 3125.
I ended up using 50 while loops calling the same code in a macro that rins 3125 loops.
This works like a charmWhile iterations = 50 M98 P"test"
And the test macro is
While iterations = 3125 ..........
-
@martin7404
I'm not sure what you mean by "did not work" and I don't understand your example.Here's a quick test.
while iterations <= 25000 if (iterations>0) && (mod(iterations, 3125) = 0) echo iterations , " is multiple of 3125" echo "done"
-
@owend I see . Most probably it is my mistake, so I did some workaround
In the main program I create a loop calling 50 times a macro that contains 3125 loops of my code with echo in the end