Adding turtle blocks

119 views
Skip to first unread message

Ivan

unread,
Aug 10, 2021, 3:52:04 PM8/10/21
to Blockly
Is there a way to add turtle blocks inside blockly?

Neil Fraser

unread,
Aug 10, 2021, 5:41:10 PM8/10/21
to blo...@googlegroups.com
Sure, here are the instructions for adding custom blocks:

We don't offer a set of movement blocks as standard since there are so many different possible variants.  Some applications want north/south/east/west movement, some want up/down/left/right movement, some want forward/backward/left/right movement, some want absolute x/y movement, some want relative x/y movement.  And within each group, some want constrained magnitudes (e.g. 1 step, 90 degrees), whereas others want unconstrained magnitudes (e.g. 4.2 steps, 22 degrees).  Some applications want computed magnitudes, others want simple built-in fields.

This is why we don't provide turtle blocks, but instead allow developers to create their own.  For reference, you might want to look at Blockly Games Turtle:
Note that even here there's a change in that levels 1-9 have constrained magnitudes, whereas level 10 has unconstrained computed magnitudes.

On Tue, 10 Aug 2021 at 12:52, Ivan <gargo...@gmail.com> wrote:
Is there a way to add turtle blocks inside blockly?

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/09c410ad-8840-4b37-9f11-2983d14f3e61n%40googlegroups.com.


--

Ivan

unread,
Aug 11, 2021, 2:29:14 AM8/11/21
to Blockly
Thank you.

Ivan

unread,
Aug 11, 2021, 3:08:07 AM8/11/21
to Blockly
But is there a way to implement some predefined turtle blocks? For example, to implement turtle blocks from blockly games?

Beka Westberg

unread,
Aug 11, 2021, 9:48:57 AM8/11/21
to blo...@googlegroups.com
Sure thing! Blockly games is open source (just like Blockly itself!) so you can grab the block definitions and block-code generators from here.

Best wishes,
Beka

Ivan

unread,
Aug 12, 2021, 3:33:24 PM8/12/21
to Blockly
Im getting error "goog is not defined". What im doing wrong?

BRr,
Ivan

Beka Westberg

unread,
Aug 12, 2021, 4:29:14 PM8/12/21
to blo...@googlegroups.com
Hello,

Those goog.X calls are something used by the closure compiler, which is something BlocklyGames uses for type checking and minification. If you just want the block definitions and block-code generators, you don't need to copy those lines =)

Best wishes,
Beka 

Ivan

unread,
Aug 13, 2021, 1:49:51 AM8/13/21
to Blockly
I tried removing those. But now error says "turtle is not defined".

Best regards,
Ivan

Beka Westberg

unread,
Aug 13, 2021, 6:50:27 PM8/13/21
to Blockly
Hello again Ivan :D

Could you paste the full text of the error? Without seeing the stack trace it's tricky to know where the issue is coming from.

Best wishes,
Beka

Ivan

unread,
Aug 14, 2021, 3:35:12 AM8/14/21
to Blockly
Hello Beka,

Really appreciate your help. Here are some screenshots. Bassically what I did. I copied turtle code without goog.require. Make a js file inside blocks and paste code there. Then in index.html I call turtle_move block. But i get error in picture.

Thank once again,
Ivan

Blockly_turtle_2.png
Blockly_turtle_1.png
Blockly_turtle_3.png

Beka Westberg

unread,
Aug 16, 2021, 9:58:02 AM8/16/21
to blo...@googlegroups.com
Hello,

I believe the problem is your first console error: "BlocklyGames is not defined" Because this error is thrown when the interpreter encounters a top-level construct, that means that the rest of the file is not getting interpreted and your blocks are not getting defined. Removing the line `BlocklyGames.NAME = 'turtle'` and any other references to BlocklyGames should fix your problem =)

Best wishes,
Beka


Reply all
Reply to author
Forward
0 new messages