statementToCode

137 views
Skip to first unread message

Julian

unread,
Sep 22, 2021, 11:37:56 AM9/22/21
to Blockly
I am developing a generator in Blockly for a custom language. I am using the function Blockly.MyLanguage.statementToCode( block, 'TheNameOfInput' ). The problem is that I can only use this function for one block. However I want to get the code for every block in the input 'TheNameOfInput'. In what way can I access the next block (eventually every block) in the same input with the function statementToCode()? 

Kind regards,

 Julian

Neil Fraser

unread,
Sep 27, 2021, 1:57:29 AM9/27/21
to Blockly
Generally each block will generate its own code, then call the generator on any next block.  Thus calling Blockly.MyLanguage.statementToCode( block, 'TheNameOfInput' ) will return the output of the entire stack, not just the one block at the top.

The mechanism for this is Blockly.Generator.prototype.blockToCode which calls the generator's scrub_ function (here's JavaScript's scrub_ as an example).  I'd recommend that your new generator have a scrub_ function that (recursively) appends the code for the next block onto the current code.

Julian

unread,
Sep 29, 2021, 12:16:01 PM9/29/21
to Blockly
Hello Neil,

Thx for your time and the solution / example . Just like you suggested I didn't have a _scrub function after finding this out it worked. However I forgot to to share that I already solved it here. 

Kind regards,

Julian


Op maandag 27 september 2021 om 07:57:29 UTC+2 schreef neil....@gmail.com:
Reply all
Reply to author
Forward
0 new messages