how to get value from a statement block of blockly in array?

2.3k views Asked by At

I am working with Blockly , and I am quite new to that. I am having a statement block there under which I am able to add some other blocks. My problem is when I am trying to convert the statement block using Blockly.JavaScript.statementToCode(block, 'io_fields') it is returning string for all the blocks combined I want it in pieces, like in an array. I don't whether this is possible or not. I didn't find any API in their documentation.

Please suggest me the way to do it. Thanks in advance.

1

There are 1 answers

0
personkfl453kmt0 On

Blockly adds all of the statement blocks up. So if you do this (from blocks_compressed text_print):

print "Hello world"
print "Hello world"

Blocks return

'window.alert("Hello world");\nwindow.alert("Hello world")'

So you can simply do this:

Blockly.JavaScript.statementToCode(block, 'io_fields').split(';\n');