Tips for writing Blockly Programs

This page is work in progress.

We provide here tips based on our experience of using Blockly.

  1. Work in Chrome to be on the safe side. (We have had crashes of Blockly with Microsoft Edge but none with Chrome). We advise you to save XML regularly to a text file because is easy to close the browser window inadvertently and to lose your assembly of blocks.
  2. When inputting an integer with the text_prompt_ext block you need to convert the returned float to an integer. We show in our range check demonstration how to do this with the math_round block.
  3. The key combination CTRL+Z can be very useful for reverting to the situation before unwanted changes.
  4. When importing blocks from XML, these will be added to the current blocks. You usually want to refresh the screen to clear it before importing.
  5. You should need to type a variable name once only so you might as well give it a longish descriptive identifier.
  6. Renaming a variable works well and changes all occurrences. You might find introduced variables that you do not want such as x, text and list. You can rename these to identifiers you need or delete them. Leave any deletions until you have completed the programming otherwise the unwanted variables may reappear. (Double clicking on a variable puts it onto the workspace then a right click gives you its drop-down menu).
  7. You can remove all redundant identifiers quickly by (1) exporting to XML, (2) pressing F5 to refresh and (3) importing from XML.
  8. You can give a procedure or function a comment by clicking on the ? icon. If you remove the default comment ("Describe this function...") it will not show up on the XML or Smart Pascal output, but will reappear the next time the blocks are imported into Blockly.
  9. In Blockly there are (as yet) no local variables - variables that are declared within procedures and functions. A variable that you use only within a routine will be declared with the other variables at the start of the program.
  10. The scale changes achieved by clicking on the + and - icons are very impressive. It is possible (but more difficult) to work with tiny blocks.
  11. You can drag the workspace around with the mouse. Do not work with blocks close to the + and - icons or your clicks may not do what you intend.
  12. To move a group of blocks, drag the top block of the group.
  13. To copy a block or group, select it and press CTRL+C then CTRL+V. It can be quicker to copy and edit than start again from the toolbox.
  14. The Home and End buttons are often useful when editing a long string of text in a block.
  15. We often use &nbsp; to represent a space, because HTML treats consecutive normal spaces as a single space. You may find it easier to enclose the string within <pre></pre> tags.
Programming - a skill for life!

A generator to help you to code in Smart Pascal