facing issues at codelab / build a custome generator course

178 views
Skip to first unread message

Masaru Ogawa

unread,
Aug 14, 2020, 1:33:49 AM8/14/20
to Blockly
Hi, trust all is well. 

I just started learning the blocky and taking the codelab course now - i am afraid perhaps i am making a very novice mistake but facing issues as below. Really appreciate your help. 

<course i am taking>

Issue is that i cannot replicate the same result as <Test it>section of the page. 
testit.PNG
instead my console says this.
myconsole.PNG

I uploaded my advanced_playground.html & custome_genetor.js in  https://github.com/masaruo11/blocklyCustomGenerat

Many thanks!

best regards,

Masaru

feni...@google.com

unread,
Aug 14, 2020, 1:33:39 PM8/14/20
to Blockly
Hi Masaru,

It looks like the code you uploaded isn't complete--your custom_generator.js only has 50 lines. Can you upload the rest of it so I can take a look?

Cheers,
Rachel

Masaru Ogawa

unread,
Aug 14, 2020, 8:08:04 PM8/14/20
to Blockly
Hi Rachel, thank you very much for the very prompt reply. 

I tried the codelab course for custome generator from start again, this time all the script is on the js file. 
Basically I am stuck at 3 - the basics (https://blocklycodelabs.dev/codelabs/custom-generator/index.html?index=..%2F..index#2) so my js code still only has 50 plus lines. 

My console shows;
custom_generator.js:55 Uncaught ReferenceError: workspace is not defined
   at toJSON (custom_generator.js:55)
   at HTMLInputElement.onclick (advanced_playground.html:414)

I also uploaded the html and js files on the below as well.
https://github.com/masaruo11/blocklyCustomGenerate  

I would be very much appreciated if you happen to have the completed code for this course so that the novice like myself can compare the code!

many thanks

best regards,

Masaru


2020年8月15日土曜日 2:33:39 UTC+9 feni...@google.com:

koz...@google.com

unread,
Aug 14, 2020, 9:02:09 PM8/14/20
to Blockly
Hello Masaru,

I took a quick look at your code and your error is about the workspace variable used in the toJSON definition L55 in custom_generator.js, however this mistake is on us (the codelab needs updating).

This codelab was written before some significant changes were made to the advanced playground and the workspace variable used to be more easily accessible in the embedded JS code on advance_playground.html (and I believe the toJSON method was meant to also be put there). The taChange function was also removed.
I am going to file an issue shortly for fixing the codelab.

To fix this issue in the meanwhile:
  • replace workspace with Blockly.getMainWorkspace()
  • remove taChange() L58 - I think this should be OK
Hopefully the rest of the codelab is fine as this issue is specific to the UI on the advanced playground and not the generator implementation.
Let us know if you encounter any other issues. I'll reply to this thread with the issue I file for updating the codelab.

~ Monica

koz...@google.com

unread,
Aug 14, 2020, 9:11:22 PM8/14/20
to Blockly

Masaru Ogawa

unread,
Aug 14, 2020, 10:43:12 PM8/14/20
to Blockly
Hi Monica, many thanks for checking the issue!

If I understand your fix correctly, I have amended the code on custom_generator.js / toJson as below. 
(i did not replace workspace with Blockly.getMainWorkspace() on advance_playground.html).
- - -
function toJSON() {
    const output = document.getElementById('importExport');
    const generatedCode = codelabGenerator.workspaceToCode(Blockly.getMainWorkspace());
    output.value = generatedCode;
    console.log(generatedCode);
    // taChange();
}
- - - 

>and I get the below error on my console. 
- - -
generator.js:182 Uncaught Error: Language "JSON" does not know how to generate  code for block type "math_number".
    at Blockly.Generator.blockToCode (generator.js:182)
    at Blockly.Generator.workspaceToCode (generator.js:94)
    at toJSON (custom_generator.js:55)
    at HTMLInputElement.onclick (advanced_playground.html:417)
- - -

Many thanks,

best regards,

Masaru

2020年8月15日土曜日 10:02:09 UTC+9 koz...@google.com:

Uwe K

unread,
Aug 15, 2020, 10:58:36 AM8/15/20
to Blockly
The error about math_number is expected and mentioned in the codelab. The next steps explain what it means and how to fix it.

Uwe K

unread,
Aug 15, 2020, 11:18:35 AM8/15/20
to Blockly
The advanced playground also doesn't contain the importExport element, so remove that part from toJSON as well:

function toJSON() {
  let workspace = Blockly.getMainWorkspace();
  let generatedCode = codelabGenerator.workspaceToCodeworkspace );
  console.log(generatedCode);
}

You'll have to open the browser console to see the result. Or use alert() instead of console.log().

Masaru Ogawa

unread,
Aug 16, 2020, 7:31:22 AM8/16/20
to Blockly
Hi Uwe, many thanks for your inputs. 

as the course is out of date, i would not going to purse this course.
Appreciate your kind inputs thought. 

many thanks

best regards,

2020年8月16日日曜日 0:18:35 UTC+9 Uwe K:

cireyoretihw

unread,
Aug 17, 2020, 5:39:17 PM8/17/20
to Blockly
i tried this also

had similar problems so i when back to the playground.html in the base directory of test

first i duplicated the simple XML rename it to json  and then added json reference by clone any "simple" reference to json ... once that worked

i replaced the XMLand put .js inline instead of
<script src="custom_generator.js"></script>

only problem the XML has bugs ... " />" and missing "</..."

this version worked ...

<xml xmlns="https://developers.google.com/blockly/xml" id="toolbox-json" style="display: none">

<block type="object"></block>
<block type="member"></block>

<block type="math_number">
<field name="NUM">0</field>
</block>

<block type="text">
<field name="TEXT"></field>
</block>

<block type="logic_boolean">
<field name="BOOL">TRUE</field>
</block>

<block type="logic_null"></block>

<block type="lists_create_with">
<mutation items="3"></mutation>
</block>

</xml>

my basic problem is the playgrounds ... ..html files did not work before modified ??


Message has been deleted

cireyoretihw

unread,
Aug 18, 2020, 2:12:58 PM8/18/20
to Blockly



i tried hard to get working from the google-blockly-3.20200625.2-0-gba68081.zip

 tests/playgrounds/advanced_playground.html

but i think missing createPlayground function is not defined

and createWorkspace function not using argument that are needed ...

not sure what it should look like ... i compared it to the tests/playground.html
but got lost in what should happen ....

just to note before assuming all source code is correct ... it might not be .....


it works so i will compare it to the .zip




cireyoretihw

unread,
Aug 18, 2020, 3:15:30 PM8/18/20
to Blockly
good news .... when i compared the online version to the .zip version
got it working only change is one line fix

change line
to
  all good now i will retry the inital problem creating the course fix ..

feni...@google.com

unread,
Aug 28, 2020, 3:54:20 PM8/28/20
to Blockly
Update: I've fixed the codelab so the instructions match the new advanced playground.

Rachel

Reply all
Reply to author
Forward
0 new messages