-
Notifications
You must be signed in to change notification settings - Fork 6
How Blockly Exports to XML
I suggest you go through the https://developers.google.com/blockly/custom-blocks/block-factory tutorial and mess around with the block editor a little bit, as it gives you some good insight on why these things are named what they are.
Block - A block in blockly. Value - A container for any "value" that exists in the form of additional blocks. The blocks evalutate out to a value. Field - A container for information that is edited directly. This contains the string or number inside a block. Type - What kind of a block the block is. Is it an if block, a variable block, etc. Statement - A section of blocks that accomplish something. They DO. Next - A connector between multiple blocks in the same statement. Comment - Text that has no effect on the output of the program.
We'll be going through the following example xml: http://pastebin.com/Riq0fTSu I suggest pulling the example into blockly while you're looking at the code, it's very helpful to keep track of things.
- You'll notice that the first block has a type, an id, and an x and y coordinate. Most importantly, notice nowhere else there are x and y coordinates; there will only be more if there are additional functions or regions of code. Note that the id's increase by one for each element. The block type defines that the block is a for_loop.
- As you head inside of blocks, you can find fields which have information, or values which contains blocks that contain information. Some blocks additionally have statements, which contain blocks that do things.
- Go to the block with ID 11. This is the set variables block within the for loop. You'll notice that instead of there being a
</block>
at the end of the block there is a<next>
. This is used to establish connections, since selecting a higher block selects the blocks below it or within it. - Follow through the statements until you reach a
</next>
. This denotes the end of a series of calls. You can see that this is where all of the</blocks>
are as well. - This continues all the way until the end of a piece of code. We can use these tags to navigate through the system.