Generate code for single block in stack only?
See original GitHub issueProblem statement
I have a stack of blocks, but I only want to generate code for a single block in that stack. Blockly however appends the generated code of subsequent blocks to the one I call Blockly.JavaScript.blockToCode() for.
The only workaround I’ve found is to detach child blocks, generate the code for the block I actually want, and then reattach them. Is there an easier way to do this?
Expected Behavior
I would like some way of getting Blockly.JavaScript.blockToCode(block)
not to call the generators of all subsequent blocks in the same stack as the one I want to generate.
Actual Behavior
All child block code is generated and automatically attached to the block’s code that I’m interested in. This causes me all sorts of issues as in on my use case I only want the code for that very specific block even though it has multiple child blocks in its stack.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Yes, so in the example I would want to get all the generated code for [B] (including any the
in list
it encloses) but not have the generator automatically generate and append the code for [C] to it.My actual use case is letting my user step through a stack of blocks one by one, so I want to generate and evaluate each block individually.
@rachel-fenichel The feature is accessed through two menu items
Generate YAIL
(admin only) andDo It
(sends to phone REPL). This relies on a function calledblockToCode1
in the YAIL generator, which basically is likeblockToCode
except it passes an additional argument toscrub_
that turns off concatenating thenextConnection
block.To back port, I think it might make sense to add the optional
opt_thisOnly
argument toblockToCode
andscrub_
so that we can collapse the two code paths. In the case of providing a menu option, one might also need a method to tell the system which language to generate. We don’t have this coded since we only have one target language.