Blockly.Python is undefined

258 views
Skip to first unread message

Julia

unread,
Oct 12, 2022, 11:07:05 AM10/12/22
to Blockly
Hi!
I updated Blockly from 7.20211209.4 to 9.0.0.
Now I've got an error: Blockly.Puthon is undefined.

This is the way my blocks was defined: 

  Blockly.Blocks['can_forward'] = {
    init: function() {
      let input = this.appendDummyInput('can_forward')
        .appendField(this.getText('can_forward'))

      input.getText = () => this.getText('can_forward')

      this.setColour('#838CD8')
      this.setTooltip('')
      this.setHelpUrl('')
      this.setPreviousStatement(false)
      this.setNextStatement(false)
      this.setOutput(true, 'Boolean')
    }
  }

  Blockly.Python['can_forward'] = function(block) {
    return [Blockly.getCode('can_forward') + "()", Blockly.Python.ORDER_NONE]
  }


`getText` -- is some custom method for Block, doesn't matter.

 The problem is (at line with Blockly.Python): 
TypeError: Cannot set properties of undefined (setting 'can_forward')   

What am I doing wrong?

Beka Westberg

unread,
Oct 12, 2022, 12:23:22 PM10/12/22
to blo...@googlegroups.com
Hello!

Before 9.0.0 the built-in generators were added to the `Blockly` object as side effects when you imported them. But this no longer happens. Instead you need to import them directly like:

```
import {pythonGenerator} from 'blockly/python';
```

You can run the @blockly/migrate script to automatically fix your imports =)

Eg:
```
npx @blockly/migrate fix-imports --from 7 ./path/to/my/files/*
```

I hope that helps! If you have any further questions please reply =)
--Beka

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/43a357cb-a514-4e29-885a-9d45854f3ac2n%40googlegroups.com.

Julia

unread,
Oct 13, 2022, 4:51:52 AM10/13/22
to Blockly
Hello, Beka! Thanks for your reply!
Unfortunately  @blockly/migrate script did nothing for me. I can't understand why.
Thanks for explainig about pythonGenerator.
As I understand it, the example in the documentation is no longer relevant?
среда, 12 октября 2022 г. в 19:23:22 UTC+3, bwes...@google.com:

Beka Westberg

unread,
Oct 13, 2022, 5:27:25 PM10/13/22
to Blockly
Hello!

Yes it looks like those docs are slightly out of date =) I've put up a fix internally and it should be up in a few days!

Thank you for bringing this to the core team's attention =)

Best wishes,
--Beka
Reply all
Reply to author
Forward
0 new messages