Blockly Turtle Graphics XML Definitions

77 views
Skip to first unread message

Masibonga Masinga

unread,
May 25, 2023, 2:49:01 AM5/25/23
to Blockly
Hi all,

I am new to blockly so Im not sure what i'm doing wrong.
I am trying to add the turtle graphics category to my on IDE thats converting every draggged block to python code.

I've run into a issue where the turtle graphics blocks are not displaying.

Blockly Version: "^6.9.0"

So Ive tried defining the blocks like this:

First Attempt
<xml xmlns="https://developers.google.com/blockly/xml" id="toolbox-categories" style="display: none">
<category name="Turtle Graphics" categorystyle="logic_category">
<category name="Pen" categorystyle="loop_category">
<block type="turtle_forward"></block>
<block type="turtle_backward"></block>
<block type="turtle_turn_right"></block>
<block type="turtle_turn_left"></block>
</category>
<category name="Drawing" categorystyle="loop_category">
<block type="turtle_pen_up"></block>
<block type="turtle_pen_down"></block>
<block type="turtle_set_color"></block>
<block type="turtle_set_width"></block>
<block type="turtle_clear_screen"></block>
</category>
</category>
</xml>

Second Attempt At defining blocks:
<category name="Turtle" colour="#745ba5">
<block type="walk_forward"></block>
<block type="turn">
<field name="NAME">left</field>
<field name="NAME">90</field>
</block>
<block type="save_state"></block>
<block type="load_state"></block>
<block type="pen_state">
<field name="pen_state">draw_y</field>
</block>
</category>


Error Message on Console:

Uncaught TypeError: Unknown block type: walk_forward
    at Blockly.Block (blockly_compressed.js:509:456)

Uncaught TypeError: Unknown block type: turtle_forward
    at Blockly.Block (blockly_compressed.js:509:456)


I am getting this error message for every type of xml block definition I try



Maribeth Bottorff

unread,
May 25, 2023, 2:52:35 PM5/25/23
to Blockly
Hello,

The code snippet you showed is a toolbox definition. The toolbox definition configures which blocks are shown in the user's toolbox. The blocks must be defined in Blockly before they can be used in a toolbox.

Based on the error message, you have not defined a block called `walk_forward` or `turtle_forward`. You can read more about creating custom blocks starting on this page.

Since you are new to Blockly, I recommend that you complete the Getting Started codelab, which will walk you through the steps of creating a Blockly application including defining blocks and defining the toolbox.

Also, I note the version of Blockly you're using is out of date - if this is a new application I'd highly recommend you use the latest version of Blockly instead.

Please let us know if you have further questions!
Maribeth

Reply all
Reply to author
Forward
0 new messages