Migrate Variable Blocks to another type

54 views
Skip to first unread message

Hermann Inzillo

unread,
Jun 26, 2021, 4:56:31 AM6/26/21
to Blockly

Hi everybody,

we have, unfortunatelly, to convert in every loaded Workspace all existing variable blocks (get and set) to a new block type.

Which is currently a custom block with dropdown fields instead of variables.

Do you have any best practice or advice for such a situation?

Currently I first tried to convert the XML, before loading the workspace. But since it is a Variable Block and we want to keep the dropdown with the variable choices. I cannot convert from XML since I do not really know all Variable options before the Workspace is created.

Now I am trying to load the workspace, create the new block with the infos from the variable_set or variable_get, connect it with the correct blocks and than delete the original one.

But this process is a bit complex to maintain and could be buggy.

Is there any better way that I have not tried?

Thank you!

Hermann

Beka Westberg

unread,
Jun 26, 2021, 10:31:47 AM6/26/21
to Blockly
Hello,

I've done some research into upgrading blocks language, and the only thing I've come accross is people modifying the XML before loading it into the workspace. Sadly there's not any best practice for this. Everyone does it a bit differently haha.

So it sounds like you're going from a block with a variable field to a block with a dropdown field? Or is it the other way around? If you're going from variables -> dropdowns, you should be able to find all of the variables by looking inside the <variables> element of the XML. For example, here is some XML containing a variable set block:
```
  <variables>  // Look in here to find all of the variables.
    <variable>test</variable>  // Note that this XML has been cleaned of IDs and things for clarity.
  </variables>
  <block type="variables_set">
    <field name="VAR">test</field>
  </block>
</xml>
```

> Now I am trying to load the workspace, create the new block with the infos from the variable_set or variable_get, connect it with the correct blocks and than delete the original one.

I think that could definitely work as well! If you decide to keep it please tell me how it goes :D

Best wishes,
--Beka

Reply all
Reply to author
Forward
0 new messages