Uncaught TypeError: Cannot read property 'getDescendants' of undefined

279 views
Skip to first unread message

M Bilel Fitouri

unread,
Mar 31, 2015, 12:17:02 PM3/31/15
to blo...@googlegroups.com
Hello,

With the new version of Blockly (31 Mars 2015), i'm getting this error when i try to generate js code of my custom block "Cron"


Uncaught TypeError: Cannot read property 'getDescendants' of undefined

This is what i see in browser console :

Blockly.Variables.allVariables
Blockly.Cron.init
Blockly.Generator.workspaceToCode
generateCronCode
blocklyController.saveScript
onclick

My code is :

var code = window.Blockly.Cron.workspaceToCode();

Blockly.Cron['api_cron'] = function(block) {
    var dropdown_day = block.getFieldValue('day');
    var dropdown_hour = block.getFieldValue('hour');
    var dropdown_minute = block.getFieldValue('minute');
    var code = '0 ' + dropdown_minute + ' ' + dropdown_hour + ' ? * ' + dropdown_day;
    return [code, Blockly.JavaScript.ORDER_NONE];
};

Blockly.Blocks['api_cron'] = {
        init: function() {
            this.setColour(165);
            this.appendDummyInput()
            .appendField("CRON :");
            ....
}



Any Idea ?

Thx

Neil Fraser

unread,
Mar 31, 2015, 1:50:37 PM3/31/15
to blo...@googlegroups.com
Take a look in Blockly.Cron.init and compare with Blockly.JavaScript.init.  This function now gets a workspace and passes it to Blockly.Variables.allVariables.  Should be an easy fix.

This change occurred three months ago as part of our slow process to get to the point where we can have multiple Blockly instances on the same page (without needing iframes).

--
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.
For more options, visit https://groups.google.com/d/optout.



--

M Bilel Fitouri

unread,
Mar 31, 2015, 2:29:26 PM3/31/15
to blo...@googlegroups.com, ro...@neil.fraser.name
It works !

Thx man, but tell me,should we define a new init method every time we have a new block ? or is it possible to use Blockly.JavaScript.init. Otherwhise, every time code change (like here with the new blockly_compressed.js),we have to change our local code 
and that's not good.

Thx again

M Bilel Fitouri

unread,
Mar 31, 2015, 2:37:37 PM3/31/15
to blo...@googlegroups.com, ro...@neil.fraser.name
It works !

Thx man, but tell me,should we define a new init method every time we have a new block ? or is it possible to use Blockly.JavaScript.init. Otherwhise, every time code change (like here with the new blockly_compressed.js),we have to change our local code 
and that's not good.

Thx again

Le mardi 31 mars 2015 19:50:37 UTC+2, Neil Fraser a écrit :

Neil Fraser

unread,
Mar 31, 2015, 2:48:51 PM3/31/15
to blo...@googlegroups.com
Blockly.JavaScript.init is used to initialize the JavaScript generator whenever code is generated from blocks.  This is different from an individual block's init, which lays out the shape of the block whenever a block is created.  Despite them both being called "init", they are completely different.

What you ran into was an extremely rare case where Blockly's API changed slightly.  That should not be a regular occurrence.
Reply all
Reply to author
Forward
0 new messages