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

    boolean expression problem, or documentation request

    Scheduled Pinned Locked Moved Solved
    Gcode meta commands
    2
    4
    78
    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.
    • mikeabuilderundefined
      mikeabuilder
      last edited by

      HW - DUet3 6HC
      RRF 3.6.0-rc.2

      I'm getting a little bit fancy developing a macro to help me run some tests on my printer. I've just run into a situation where I the boolean-expression in an IF statement that is evaluating whether a string is equal to an integer. For example:

      if "some_string"  =  1
      

      I expected this to evaluate to false - a string can never equal a number. But I get an error message:

      Error: in file macro line 1 column 14: meta command: cannot convert operands to same type
      

      If my assumption is bad about this expression evaluating to false, then maybe the meta command doc should say something about this.

      dc42undefined 1 Reply Last reply Reply Quote 0
      • dc42undefined
        dc42 administrators @mikeabuilder
        last edited by

        @mikeabuilder RRF takes the view that when comparing values for equality, you should know what the types are, therefore it is a static error if you compare different types. It's the same as evaluating "some_string" + 1. An exception is if you check a value for equality with the constant null because there are some values in the Object Model may be null or may have a value.

        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

        1 Reply Last reply Reply Quote 0
        • mikeabuilderundefined
          mikeabuilder
          last edited by

          @dc42 - thanks for explaining that. In my use case, I was building an array to fill in later with numbers and was using text as a placeholder when I created the array. I switched to null as my placeholder and now it works great.

          dc42undefined 1 Reply Last reply Reply Quote 0
          • dc42undefined
            dc42 administrators @mikeabuilder
            last edited by

            @mikeabuilder I'm glad you got it working. I have updated the documentation.

            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

            1 Reply Last reply Reply Quote -1
            • 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