Duet3D Logo

    Duet3D

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • Documentation
    • Order

    Solved Determining the length of an array of values

    Gcode meta commands
    2
    3
    77
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • hlwerschner
      hlwerschner last edited by

      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?

      OwenD 1 Reply Last reply Reply Quote 0
      • OwenD
        OwenD @hlwerschner last edited by

        @hlwerschner
        You can use # to get the size of the array

        while iterations < #sensors.endstops
           echo sensors.endstops[iterations].triggered
        
        hlwerschner 1 Reply Last reply Reply Quote 0
        • hlwerschner
          hlwerschner @OwenD last edited by

          @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.

          1 Reply Last reply Reply Quote 0
          • Topic has been marked as a question  dc42 dc42 
          • Topic has been marked as solved  dc42 dc42 
          • First post
            Last post
          Unless otherwise noted, all forum content is licensed under CC-BY-SA