Blockly code generation - creating comments

34 views
Skip to first unread message

Alan Smith

unread,
Mar 2, 2026, 4:05:13 PMMar 2
to blo...@googlegroups.com
There are a wide variety of gamepads on the market.   Including such terrible features as different "standards" for what you call the four buttons on the right side.

The SDL calls these "north, south, east and west" facing buttons.    However, this is confusing for students (who often don't know their cardinal directions) so we display the dropdown choices as the labels on the particular button.

However, at the block that generates the code "is_pressed(SOUTH_FACE)" which knows it was the A button - it can't generate a comment because that could be in the middle of a code line.

What I would like is some way to give comments that go either at the end or previous to the code line being generated.

So for example you would see:

if is_pressed(SOUTH_FACE):  # A is SOUTH_FACE on xbox controller

or for a more complicated example:

if is_pressed(SOUTH_FACE) and is_pressed(NORTH_FACE): # A is SOUTH_FACE on xbox controller, Y is NORTH_FACE on xbox controller

another possibility would be:
# A is SOUTH_FACE on xbox controller
# Y is NORTH_FACE on xbox controller
if is_pressed(SOUTH_FACE) and is_pressed(NORTH_FACE): 

any ideas on how to do this in a reasonable way?

Thanks in advance,

Alan

Mark Friedman

unread,
Mar 2, 2026, 5:26:42 PMMar 2
to blo...@googlegroups.com
Alan,

  The CodeGenerator.scrub_ method (doc here) is generally where this sort of thing is handled.  Take a look at JavascriptGenerator.scrub_ method (code here) for an example that handles comments.  The other language generators have similar code in their scrub_ methods.

  Hope this helps.

-Mark


--
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 visit https://groups.google.com/d/msgid/blockly/CAEviOuhowdVA9%3DVxrN52vGXtskz37W4PTAtQZP0BxjMtiLWAzA%40mail.gmail.com.

Adam Bryant

unread,
Mar 3, 2026, 3:38:04 AMMar 3
to blo...@googlegroups.com
I have python comments in my blocks like this:
#—-This comment because I forget —-

It’s in the code generator and when my version shows generated code it displays the comments with no problem. 
If you use JavaScript the comment must be //—-This comment because I forgot—-

One point I did notice is do not use apostrophes, commas and other special characters or blockly gets confused 
Sent from my iPhone

On 2 Mar 2026, at 22:26, Mark Friedman <mark.f...@gmail.com> wrote:


Reply all
Reply to author
Forward
0 new messages