Blockly code generation - creating comments

5 views
Skip to first unread message

Alan Smith

unread,
4:05 PM (8 hours ago) 4:05 PM
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,
5:26 PM (7 hours ago) 5:26 PM
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.
Reply all
Reply to author
Forward
0 new messages