Determining the length of an array of values
-
As the title says, I need a meta command function - I could not identify an existing one - to extract the length of an array. The object model has several places where it collects some values into an array ( example : sensors.endstops[] ) but I have not seen an example gcode how to iterate through such an array within a macro. I need to check the state of an endstop switch but as long as I do not know which of the sensors.endstops[i] elements belongs to which axis, I have to look through the complete array ... The sensors.endstops[i].type is too vague to find a match, perhaps it would be nice to also have the associated axis available in this array.
How can I achieve this without macro errors - because of array index overflowing? -
@hlwerschner
You can use # to get the size of the arraywhile iterations < #sensors.endstops echo sensors.endstops[iterations].triggered
-
@owend Oh yeah, I have overread this! Thank you...I had expected this to be a "function" like length() or var.length ...
mea culpa for to scanning the docs more intensively. -
-