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

Function exists() does not work correctly with array elements.

Scheduled Pinned Locked Moved
Documentation
3
4
270
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic was forked from Meta gcode result variable inconsistent with docs T3P3Tony 14 Feb 2024, 14:43
This topic has been deleted. Only users with topic management privileges can see it.
  • undefined
    NineMile @NineMile
    last edited by NineMile 13 Feb 2024, 18:53

    Found another interesting behaviour, although this specific behaviour is undocumented - exists() does not work on vectors, so say for example calling exists(global.vector[12]) simply returns the value of global.vector[12] if it exists and throws an invalid index error if global.vector[12] does not exist.

    The obvious way around this is to check the indexes but it would be good if this behaviour was at least documented, and at best either implemented, or made so calling exists on a member of a vector generates an error rather than essentially being a no-op. Finding this was rather confusing as I was calling it on a vector of booleans.

    undefined undefined 2 Replies Last reply 14 Feb 2024, 14:43 Reply Quote 0
    • undefined
      T3P3Tony administrators @NineMile
      last edited by 14 Feb 2024, 14:43

      @NineMile

      Thanks for pointing out the limitation in exists() as far as it comes to arrays. As you say the work around at this point is to use:

      #global.vector
      to check the array length

      that does not get around the returning of the value from the array, rather than a boolean I tested it with this example:

      global testArray = {1,2,3,4}
      echo exists(global.testArray[2])
      3

      this is clearly not a boolean response!

      please would you raise a bug report for this and reference this thread.

      www.duet3d.com

      1 Reply Last reply Reply Quote 0
      • undefined
        dc42 administrators @NineMile
        last edited by 16 Feb 2024, 09:27

        @NineMile thanks for reporting this. I've fixed it in the 3.5-dev source code. I wasn't able to reproduce a problem with the second example you have in your issue report.

        Duet WiFi hardware designer and firmware engineer
        Please do not ask me for Duet support via PM or email, use the forum
        http://www.escher3d.com, https://miscsolutions.wordpress.com

        undefined 1 Reply Last reply 16 Feb 2024, 11:07 Reply Quote 1
        • undefined
          NineMile @dc42
          last edited by NineMile 16 Feb 2024, 11:07

          @dc42 I realise now I wasn't actually checking the tools array like that, I was checking a global vector storing additional tool details { vector(limits.tools, {radius, {deflection-x, deflection-y}}) } which is linked to the defined tool, so the existing fix should cover all of my usages. Thanks!

          1 Reply Last reply Reply Quote 0
          1 out of 4
          • First post
            1/4
            Last post
          Unless otherwise noted, all forum content is licensed under CC-BY-SA