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

    Global Variable Question

    Scheduled Pinned Locked Moved
    Gcode meta commands
    4
    21
    1.2k
    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.
    • DonStaufferundefined
      DonStauffer @fcwilt
      last edited by

      @fcwilt Having now explored variables and pondered syntax and usage cases, I think I should say this: Between the addition of variables, conditionals, and loops, the macro capability of RRF just pulled a "Wizard of Oz" and went from black and white to Technicolor. So many things are now possible that just weren't before!

      RRF 3.3 is profoundly richer than previous versions. Giant leap forward!

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

        @donstauffer said in Global Variable Question:

        And right now exists() always returns False.

        Please explain what you mean by that. You should be able to use

        exists(global.myvar)
        

        to test whether a global variable has been created yet.

        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

        DonStaufferundefined 1 Reply Last reply Reply Quote 1
        • DonStaufferundefined
          DonStauffer @dc42
          last edited by

          @dc42 My testing in error. exists() works fine.

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

            @fcwilt said in Global Variable Question:

            Would it be helpful to have a variable scope that would be visible to any macros called from the macro where the variable was created?

            That should already be the case for local variables created using var.

            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

            DonStaufferundefined 1 Reply Last reply Reply Quote 0
            • DonStaufferundefined
              DonStauffer @dc42
              last edited by DonStauffer

              @dc42

              Macro "Caller":
              var X = 3
              M98 P"/macros/Test/Callee"

              Macro "Callee":
              echo "X="^{var.X}

              Result of running Caller:
              Error: in file macro line 1 column 17: meta command: unknown variable 'X'

              (This is fine with me. As expected.)

              dc42undefined 1 Reply Last reply Reply Quote 1
              • fcwiltundefined
                fcwilt @DonStauffer
                last edited by

                @donstauffer said in Global Variable Question:

                When would you use a "semi-global" (downstream scope?) like that?

                If the development of "macro packages" were to become popular that kind of scope could limit the need for global variables and thus reduce possible conflict with other "macro packages".

                Not a huge issue to be sure but if it was something that was fairly easy to do with no real downside it might be something to consider.

                Frederick

                Printers: a E3D MS/TC setup and a RatRig Hybrid. Using Duet 3 hardware running 3.4.6

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

                  @donstauffer said in Global Variable Question:

                  @dc42

                  Macro "Caller":
                  var X = 3
                  M98 P"/macros/Test/Callee"

                  Macro "Callee":
                  echo "X="^{var.X}

                  Result of running Caller:
                  Error: in file macro line 1 column 17: meta command: unknown variable 'X'

                  (This is fine with me. As expected.)

                  Thanks. I've added this to my list for checking, and to consider what behaviour is most desirable.

                  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
                  • gloomyandyundefined
                    gloomyandy @fcwilt
                    last edited by

                    @fcwilt I'm curious which programming languages allow access to local variables from other functions in this way? The only ones I can think of off the top are my head are ones like Pascal but in that case the procedure/function definition is within the same scope as the "local" variable and so makes more sense. Allowing dynamic access to local variables is not something I've come across.

                    fcwiltundefined DonStaufferundefined 2 Replies Last reply Reply Quote 0
                    • fcwiltundefined
                      fcwilt @gloomyandy
                      last edited by

                      @gloomyandy said in Global Variable Question:

                      @fcwilt I'm curious which programming languages allow access to local variables from other functions in this way? The only ones I can think of off the top are my head are ones like Pascal but in that case the procedure/function definition is within the same scope as the "local" variable and so makes more sense. Allowing dynamic access to local variables is not something I've come across.

                      Pascal (actually Delphi) as you have noted.

                      Since Delphi supports objects it also has the concept of object members/methods having private, protected and public scope.

                      A member/method with private access is accessible only from the class in which it is declared.

                      A member/method with protected access is accessible from sub-classes.

                      A member/method with public access is accessible from all other classes.

                      Frederick

                      Printers: a E3D MS/TC setup and a RatRig Hybrid. Using Duet 3 hardware running 3.4.6

                      1 Reply Last reply Reply Quote 0
                      • DonStaufferundefined
                        DonStauffer @gloomyandy
                        last edited by

                        @gloomyandy C++ has something like Pascal has, in that you can create local constructs within a function, and the function becomes the enclosing scope and so is accessible. It's been too long and I don't remember the details.

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