Tips for writing Blockly Programs
This page is work in progress.
We provide here tips based on our experience of using Blockly.
- 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.
- 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.
- The key combination CTRL+Z can be very useful for reverting to the situation before unwanted changes.
- 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.
- You should need to type a variable name once only so you might as well give it a longish descriptive identifier.
- 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).
- You can remove all redundant identifiers quickly by (1) exporting to XML, (2) pressing F5 to refresh and (3) importing from XML.
- 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.
- 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.
- The scale changes achieved by clicking on the + and - icons are very impressive. It is possible (but more difficult) to work with tiny blocks.
- 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.
- To move a group of blocks, drag the top block of the group.
- 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.
- The Home and End buttons are often useful when editing a long string of text in a block.
- We often use 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.