Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Determining the length of an array of values

    Scheduled Pinned Locked Moved Solved
    Gcode meta commands
    2
    3
    200
    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.
    • hlwerschnerundefined
      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?

      OwenDundefined 1 Reply Last reply Reply Quote 0
      • OwenDundefined
        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
        
        hlwerschnerundefined 1 Reply Last reply Reply Quote 0
        • hlwerschnerundefined
          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
          • dc42undefined dc42 marked this topic as a question
          • dc42undefined dc42 has marked this topic as solved
          • First post
            Last post
          Unless otherwise noted, all forum content is licensed under CC-BY-SA