How to indent functions that Blockly blocks output

223 views
Skip to first unread message

Gil Creque

unread,
Jun 28, 2022, 10:40:18 AM6/28/22
to Blockly
Hello.

I am using Blockly to generate Python code for various games we have on our platform. The player code is extending an existing class so it requires all the functions to be indented under that class. I have figured out how to do this for the custom block I have added. I am using the indent-string library. I would like to do the same for every Blockly function that is generated but I cannot figure out how to hook into that. Any pointers would be much appreciated. 

Thank you.

Screen Shot 2022-06-28 at 10.33.30 AM.png

Neil Fraser

unread,
Jun 28, 2022, 11:05:01 AM6/28/22
to blo...@googlegroups.com
This may not completely answer your question, but have you seen:
code = Blockly.Python.prefixLines(code, Blockly.Python.INDENT + Blockly.Python.INDENT);

It's all inherited from Generator:


--
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/ff038359-91bc-49f2-8a0d-fc9ad9818af1n%40googlegroups.com.


--

Gil Creque

unread,
Jun 29, 2022, 12:10:45 PM6/29/22
to blo...@googlegroups.com
Thanks, Neil!

That bit of code allowed me to get rid of the indent library I was using. I ran into other issues when generating code expected to be in a class doesn't quite have what you need. The self keyword is a big one. 


Reply all
Reply to author
Forward
0 new messages