I'm trying to generate arduino C code using scratch block. I can't store generated code because of vm architecture. For example, this is code for builtin 'if' statement
if (args, util) {
const condition = Cast.toBoolean(args.CONDITION);
if (condition) {
util.startBranch(1, false);
}
}
I want to make something like this:
if (args, util) {
const condition = Cast.toString(args.CONDITION);
const body = recursive_call_for_inner_blocks(inner_blocks);
return `if (${condition}) { ${body} }`;
}
How can I do this? Maybe there is a better way to generate code using scratch blocks?
scratch-vm is not made for such purpose - it's made for executing Scratch project. I'm sure there are some open-source arduino generator using Scratch 3.0.
@apple502j I have only found forks with firmata (no code generation, only live control). Can you give me examples please?
Hmm yeah most of my search results are in older versions... @caxapexac I think you should parse the JSON, though. For example, args.CONDITION is NOT the passed condition (like even if you pass timer > 10, CONDITION is executed value (true or false))
@caxapexac
Can you give me examples please?
It's Smalruby ( https://github.com/smalruby/smalruby3-gui/ and https://smalruby.jp/smalruby3-gui/ ) that is forked from scratch-gui.
Smalruby can generate from scratch's block to ruby code. And it can convert ruby code to scratch's blocks.
Related code is here:
Thank you! I'll try it out
@caxapexac scratch-blocks was originally branched from Blockly, which does convert blocks into code. It may be easier for you to start there: https://developers.google.com/blockly