"Identifier redefined as global" error when using Blockly functions
-
@m5stack I have this program in uiFlow (v1.6.2 or v1.4.5, it doesn't matter)
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.
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.
-
@world101
In UIFlow defined variables are every time global. Using local variables in UIFlow only works in execute blocks. -
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.
-
@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):
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 errorwhen switching to </>Python - page you can see that UIFlow made incorrect code transformation:
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 missingAs 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! -
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
-
@lukasmaximus on my IPad ist seems to work fine, the problem occured on a WIN10 pc, tomorrow i try it again on WIN10.
-
@lukasmaximus for my win10-pc the problem also seems to be solved, many thanks
-
Hi, is this bug has been resolved? Seems the bug is still there.
-
I have the same issue. Has this been fixed ? Thanks !