upgrade blockly

67 views
Skip to first unread message

fajar rokhman

unread,
Jun 20, 2024, 1:28:08 PM (9 days ago) Jun 20
to Blockly
Hi, 

I have just upgraded to the new blockly, and found my app crashes. so I try the
the new typescript example, to see what has probably changes. but also  find probem..

There is a sample of block definition. This block definition doesn't mention anything about shadow input. But I can see a shadow input in the runtime. I don't understand how the new shadow input works, and how we define in the block definition.

I try to add new entry to the existing example, but don't see the new item.

export const blocks = Blockly.common.createBlockDefinitionsFromJsonArray([
    addText,
    {
        type: 'add_text2',
        message0: 'Add text %1 test3',
        args0: [
            {
                type: 'input_value',
                name: 'TEXT',
                check: 'String',
            },
        ],
        previousStatement: null,
        nextStatement: null,
        colour: 160,
        tooltip: '',
        helpUrl: '',
    }
]);


Is there anything wrong? I just duplicate the entry and change the Id.

thanks.

Maribeth Moffatt

unread,
Jun 20, 2024, 3:04:06 PM (9 days ago) Jun 20
to Blockly
Hello,

A block definition only defines one block at a time. The `add_text2` block is a block that has one value input.

Shadow blocks are separate blocks that are connected to another block's inputs.

If you want to add shadow blocks to another block's inputs, that isn't done in the basic block definition. The easiest way to add shadow blocks to the connections of a regular block like you have here is to use the toolbox definition. In your toolbox definition, you can specify that certain blocks come connected together, or fields have specific values, etc. In the sample app, we add the shadow block in the toolbox definition here.

On another note, if you would like to update your Blockly version, the best place to learn about changes is in the release notes. Each of the "breaking changes" PRs listed should have a section in the PR description explaining what changed and what you might need to fix. If you had any deprecation warnings in the console when using the previous version, you'll also want to address those because some APIs may have been removed or renamed.

I hope that helps! Let us know if you have additional questions.

Best,
Maribeth

fajar rokhman

unread,
Jun 23, 2024, 3:34:24 PM (6 days ago) Jun 23
to Blockly
Hi, Thanks for the answer.

I'm trying to load blockly workspace from json, through Blockly.serialization.workspaces.load() command.

And encounter this error.
TypeError: Invalid block definition for type: math_number
    at new Block$$module$build$src$core$block (blockly_compressed.js:975:1)
    at new BlockSvg$$module$build$src$core$block_svg (blockly_compressed.js:1227:1)
    at WorkspaceSvg$$module$build$src$core$workspace_svg.newBlock (blockly_compressed.js:1645:1)
    at appendPrivate$$module$build$src$core$serialization$blocks (blockly_compressed.js:184:1)
    at appendInternal$$module$build$src$core$serialization$blocks (blockly_compressed.js:181:1)
...

I don't know what's wrong with the data:
{
    "blocks": {
        "languageVersion": 0,
        "blocks": [
            {
                "type": "ha.be.Be.Start",
                "id": "ttDi6Y1piNqKi!GKH=;f",
                "x": 249,
                "y": 198,
                "inputs": {
                    "width": {
                        "shadow": {
                            "type": "math_number",
                            "id": "!n`U},x?W~b8S2S9fc;-",
                            "fields": {
                                "NUM": 320
                            }
                        }
                    },
                    "height": {
                        "shadow": {
                            "type": "math_number",
                            "id": "(i=R@FswM^]Ps$?-8bzQ",
                            "fields": {
                                "NUM": 240
                            }
                        }
                    },
                    "statementst": {
                        "block": {
                            "type": "variables_set",
                            "id": "?BBuRH-xfVFsVL#ivCx)",
                            "fields": {
                                "VAR": {
                                    "id": "99*3xs_.J9FLSB`sp](v"
                                }
                            },
                            "inputs": {
                                "VALUE": {
                                    "block": {
                                        "type": "ha.be.Spr.Muat",
                                        "id": "-Wwr3nwkx~$;z$;b1tzu",
                                        "inputs": {
                                            "url": {
                                                "shadow": {
                                                    "type": "text",
                                                    "id": "tjz/~)*VQIRK@:47=aoI",
                                                    "fields": {
                                                        "TEXT": "./imgs/box.png"
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            },
            {
                "type": "ha.be.Be.Update",
                "id": "D!_p@;(TK|!Jb;q9U}?k",
                "x": 389,
                "y": 333,
                "inputs": {
                    "statementst": {
                        "block": {
                            "type": "ha.be.Be.Bersih",
                            "id": "(7d4VY9ISHI3=xQXw=c0",
                            "next": {
                                "block": {
                                    "type": "ha.be.Spr.Gambar",
                                    "id": "TKi]Pbe|YLS%b}yYe+1L",
                                    "inputs": {
                                        "sprite": {
                                            "block": {
                                                "type": "variables_get",
                                                "id": "Oxp^k?rAe(XG%z7DGmrI",
                                                "fields": {
                                                    "VAR": {
                                                        "id": "99*3xs_.J9FLSB`sp](v"
                                                    }
                                                }
                                            }
                                        },
                                        "x": {
                                            "shadow": {
                                                "type": "math_number",
                                                "id": "iR^9X(~I02#.l.kt.[;:",
                                                "fields": {
                                                    "NUM": 120
                                                }
                                            }
                                        },
                                        "y": {
                                            "shadow": {
                                                "type": "math_number",
                                                "id": "Sn*[t/Kt[]3J~cg5t9-K",
                                                "fields": {
                                                    "NUM": 100
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        ]
    },
    "variables": [
        {
            "name": "image",
            "id": "99*3xs_.J9FLSB`sp](v"
        }
    ]
}

the math_number seems to have a correct structure.

I have many project saved as json and I'm affraid I cannot open in the new version.

Maribeth Moffatt

unread,
Jun 23, 2024, 3:43:01 PM (6 days ago) Jun 23
to Blockly
The error happens because Blockly doesn't know about a block named "math_number" -- usually this happens for built-in blocks because you haven't loaded them yet.

In order to use the built-in blocks, you need to load them somehow before you try to reference them. If you're using import statements, that would look like
 `import * as libraryBlocks from 'blockly/blocks';` 

if you're using requires or script tags there are examples at the link above. This just needs to be done once per page load but it must be done before you try to use the block type.

Best,
Maribeth

fajar rokhman

unread,
Jun 26, 2024, 5:15:23 AM (3 days ago) Jun 26
to Blockly
Finally I can fix it by changing from
import * as Blockly from 'blockly/core';

to:
import * as Blockly from 'blockly';

I previously not working with npm verion of blockly. So it is kind of new experience. 

Thanks for your help. 
Reply all
Reply to author
Forward
0 new messages