🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    "Identifier redefined as global" error when using Blockly functions

    Bug Report
    5
    9
    16.6k
    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.
    • world101W
      world101
      last edited by

      @m5stack I have this program in uiFlow (v1.6.2 or v1.4.5, it doesn't matter)
      0_1598132036682_Screen Shot 2020-08-22 at 5.33.16 PM.png

      This is the resulting python code and it successfully runs:

      localVarX = None
      localVarY = None
      global globalVarA, globalVarB
      global globalVarA, globalVarB
      
      def myFunction(localVarX, localVarY):
        global globalVarA, globalVarB
        pass
      
      global globalVarA, globalVarB
      global globalVarA, globalVarB
      

      However, when I try to set or change the local variables (localVarX and localVarY) within the function, uiFlow redefines them as global variables in the function and I get an error on the m5stickC when I run the program.
      0_1598132273836_Screen Shot 2020-08-22 at 5.36.56 PM.png

      New python code:

      localVarX = None
      localVarY = None
      global globalVarA, localVarX, globalVarB, localVarY
      global globalVarA, localVarX, globalVarB, localVarY
      
      def myFunction(localVarX, localVarY):
        global globalVarA, localVarX, globalVarB, localVarY
        localVarX = 3
        localVarY = 4
      
      global globalVarA, localVarX, globalVarB, localVarY
      global globalVarA, localVarX, globalVarB, localVarY
      
      

      Here is the error on the serial monitor:

      Traceback (most recent call last):
        File "flow/m5cloud.py", line 76, in _exec_fun
        File "<string>", line 13, in <module>
      SyntaxError: identifier redefined as global
      

      Running the same function on the Blockly Playground, it seems to work correctly.
      0_1598132832681_Screen Shot 2020-08-22 at 5.44.43 PM.png
      0_1598132843034_Screen Shot 2020-08-22 at 5.45.25 PM.png

      G 1 Reply Last reply Reply Quote 0
      • G
        Gaviota @world101
        last edited by

        @world101
        In UIFlow defined variables are every time global. Using local variables in UIFlow only works in execute blocks.

        A lot of nice M5Stack stuff :) ....

        world101W 1 Reply Last reply Reply Quote 0
        • world101W
          world101 @Gaviota
          last edited by

          @gaviota

          Thanks for confirming. I think this is indeed a bug in uiFlow then. I shouldn't have to use the execute block to work with local variables in the functions. Especially if Blockly Playground behaves differently.

          G 1 Reply Last reply Reply Quote 0
          • G
            Gaviota @world101
            last edited by Gaviota

            @lukasmaximus @m5stack @ajb2k3 @admin
            Critical bug with the word "global" at python code transformation from UIFlow 1.6.2

            @world101
            ... i agree with you, there is a critical bug in UIFlow 1.6.2.

            E.g. using the word "global" causes the python code transformation to replace the following text with all defined variables. Or defining a function with parameters causes a global definition in this function with the given paramater (look at my short test_global-program):
            0_1598192973024_global1.jpg

            with variables: value, var01
            var01 is set to "Bug with text global"

            In function "dosomething" with given parameter "value" i placed an Execute-code block with following content:
            # Test function for global error
            # look for global error
            # look for Global error

            when switching to </>Python - page you can see that UIFlow made incorrect code transformation:
            0_1598193335312_global2.jpg

            This code cann not run because:
            Line 17: the identifier "value" is redifined as global
            Line 27: the text after the word "global" is replaced by "var01, value" and the closing quotation mark is missing

            As you can see, each time the word "global" appears, the following text is replaced by all defined variables (see lines 18, 19 and 27).

            In line 20, the word "global" begins with a capital letter which doesn't lead to mistakes in code transformation.

            Note:
            With UIFlow 1.6.1 desktop version this problem does not exist!

            A lot of nice M5Stack stuff :) ....

            1 Reply Last reply Reply Quote 1
            • lukasmaximusL
              lukasmaximus
              last edited by

              I just started to get this error today too when trying an m5f file that had previously worked fine. Thanks for highlighting this guys, I'll create a bug report

              G 2 Replies Last reply Reply Quote 0
              • G
                Gaviota @lukasmaximus
                last edited by Gaviota

                @lukasmaximus on my IPad ist seems to work fine, the problem occured on a WIN10 pc, tomorrow i try it again on WIN10.

                A lot of nice M5Stack stuff :) ....

                1 Reply Last reply Reply Quote 0
                • G
                  Gaviota @lukasmaximus
                  last edited by

                  @lukasmaximus for my win10-pc the problem also seems to be solved, many thanks

                  A lot of nice M5Stack stuff :) ....

                  1 Reply Last reply Reply Quote 0
                  • B
                    beacon88
                    last edited by

                    Hi, is this bug has been resolved? Seems the bug is still there.

                    1 Reply Last reply Reply Quote 0
                    • N
                      natcl
                      last edited by

                      I have the same issue. Has this been fixed ? Thanks !

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post