When dragging functions into a library, also move their variables

Issue #339 resolved
Wenjie Wu created an issue

When a function definition is dragged into a library, any global variables used by that function should be moved from the top-level project into the library. Currently, the function is moved but the variables are not. Thus, when the library is exported, it does not include the variables it depends on.

Original problem description:

Export a new library, all variables are not exported. IDE 1.2.5 had this problem, something seems to be broken.

Comments (11)

  1. John Maloney repo owner

    I can't reproduce this problem with variables "foo" and "bar". I wonder if the problem may occur when certain characters appear in the variable name. How can I reproduce the problem?

  2. John Maloney repo owner

    Thanks for the example. However, I'm not seeing the issue.

    I created a _test variable, then made a command as shown. Then I did "export functions as library" and I got:

    module tmp
    author unknown
    version 1 0 
    description ''
    variables _test
    
      spec ' ' 'myBlock' 'myBlock'
    
    to myBlock {
      _test = 0
    }
    

    That looks correct. Note that variables not referenced by any of the exported functions are not included in the exported library by design. That allows one to create some functions in a project containing a lot of other libraries and their variables. When you export those functions as a library, that library will not include the variables from the other libraries.

    And, of course, variables that start with an underscore are only shown in "advanced block" mode.

    FYI, I tested this in both the stand-alone version of 1.2.6 and in the 1.2.5 web app.

  3. Wenjie Wu reporter

    hi John,

    Sorry I didn't describe my problem clearly, I used this export method: expot this library

    and I got:

    module mylib
    author unknown
    version 1 0 
    description ''
    
      spec ' ' 'myBlock' 'myBlock'
    
    to myBlock {
      _test = 0
    }
    

    FYI, I tested this in v1.2.5 web app.

    here is my project

  4. John Maloney repo owner

    I see the problem.

    In your project, the variable is owned by the top-level project but the myBlock script that references the variable is in the library. Thus, when you export the library, it doesn't include the variable because it doesn't "own" that variable.

    How did you create the project and the library? I'm guessing you created a new library, created the variable, then created a script and dragged it into the library. That's a perfectly reasonable way to make a library. If so, the bug is that the variable should have been moved from the top-level project into the library when you dragged the script. We'll fix that.

    Meanwhile, you can manually fix the problem by opening the .ubl file in a text editor and adding a "variables" line with the missing variable(s).

    If you created the project some other way, let me know what you did. The bug isn't actually in "export this library" it is in the library creation process.

  5. Wenjie Wu reporter

    I'm guessing you created a new library, created the variable, then created a script and dragged it into the library. That's a perfectly reasonable way to make a library. If so, the bug is that the variable should have been moved from the top-level project into the library when you dragged the script. We'll fix that.

    Yes John, This is exactly how I created the library, which I guess is why Apple is having problems.

    Meanwhile, you can manually fix the problem by opening the .ubl file in a text editor and adding a "variables" line with the missing variable(s).

    I used this method to help Apple solve his problem yesterday.

  6. John Maloney repo owner

    Just updated the issue title and description. Will fix this but, meanwhile, many thanks for helping Apple work around the problem.

  7. Log in to comment