StatementToCode with Custom Blocks

390 views
Skip to first unread message

Sofia Galan Bataller

unread,
Sep 12, 2019, 5:19:52 PM9/12/19
to Blockly
Hello,

I looked for answer to my very simple question however I think I might be missing something.  I'm tying to understand how to obtain data contained in block that has other blocks on it.


This are my code generators, 

Blockly.JavaScript['object'] = function(block) {
 var dropdown_value = block.getFieldValue('VALUE');
 var statements_object = Blockly.JavaScript.statementToCode(block, 'variablex'); /* <----- Here is my doubt when I try to connect a custom block*/
var code = 'Value Object:'+ dropdown_value + 'Statements:'+ statements_object;
 console.log(code); /* I'm getting nothing in statement_objects because I think it doesn't undestand what variablex is*/
 return (code);
};

Blockly.JavaScript['variablex'] = function(block) {
 var number_x = block.getFieldValue('X');
 var code = 'pos'+ number_x+';\n';
 console.log("Value VariableX"+ code);
 return (code);
};


When I try to input this blocks:
- I get the both unique blocks in my console.log and in my  javascript output code
- The cluster of blocks only prints the 'Objeto' or the purple one surrounding the little blocks in my console.log and javascript output code
- I get a null from staments_objects


Captura de Pantalla 2019-09-12 a la(s) 16.12.37.png

 
I want to learn how to read StatementToCode of Custom Blocks if possible,


Thank you in advance! I hope I was clear enough, if something doesn't make sense please let me know. 

- Sofia





Monica Kozbial

unread,
Sep 12, 2019, 7:08:05 PM9/12/19
to Blockly
Hi Sofia,

From looking at your code, I think the issue is that you aren't passing the right name in your call to statementToCode in the 'object' block generator. Instead of passing 'variableX', I think you'll need to pass the name that you assigned to that input_statement in the 'object' block definition.
I hope that helps! Otherwise, it might be useful to also share the block definitions for 'object' and 'variableX' blocks.

~ Monica

Ray gautam

unread,
Sep 14, 2019, 3:35:44 AM9/14/19
to Blockly
yep she is right .. do what moncia says 

Sofia Galan Bataller

unread,
Sep 17, 2019, 4:07:03 PM9/17/19
to Blockly
Thank you Monica I see where my error was! :) 
Reply all
Reply to author
Forward
0 new messages