Snap blocks are assembled in an open white area, called the workspace. Here are a few tips for using the Snap workspace effectively.
Icons
In the upper-right corner of a Snap workspace are a series of icons to help you work.
- Schedule all the code in the workspace to run only during a specific window of time. If a schedule is in place, this icon is a different color. This feature is rarely used.
- Zoom in to make the Snap blocks appear larger.
- Zoom out to make them smaller.
- Enlarge the snap workspace to fill the entire screen. Helpful when you want an immersive coding environment. Click the icon again (or press the ESC key) to restore the workspace.
- Clean up your workspace. Any Snap blocks which are disconnected from the initial green-colored block are deleted.
- Undo the last edit.
- Redo the last undone edit.
- View the Snap blocks in JSON format. This view is read-only.
- View the Snap blocks in JavaScript format. This view is read-only.
Hotkeys
While in a Snap workspace...
- Scroll up or down with the mouse wheel.
- Zoom in or out with CTRL + mouse wheel.
- Undo the last change with CTRL + Z.
- Redo that change with CTRL + Y.
- Select one block by clicking the block: it will change color.
- Select a range of blocks by clicking one block, holding down SHIFT, and clicking another block to select the range of connected blocks between them.
-
With a single block or range of blocks selected,
- Move by dragging. Any blocks connected below your selection will follow along.
- Splice out selections by SHIFT - dragging them. Any blocks connected below them will remain in place.
- Copy selections by CTRL - dragging them. Any blocks connected below them are not copied.
- Delete them by pressing the DEL key.
Finding errors
If the Snap code has any syntax errors which can be caught during design – such as a type mismatch – the errors are easy to find and fix. The admin interface calls your attention to syntax errors in four different ways:
- Troublesome blocks will be highlighted in red.
- A full description of the error will appear at the bottom of the Snap workspace.
- If the error is within a configurator, the icon for the rule containing the error changes.
- If the error is within a configurator, a count of all errors throughout the entire configurator is always visible in the upper-right corner when editing that configurator.
Fixing errors
- Click any red Snap block to see a pop-up with details on the error. The details often contain clickable "fix this" text that will analyze the error and propose a possible solution.
- Click the "fix this" link also shown in the error description at the bottom of the workspace containing the red block.
- Click any red Snap rule to open the troublesome rule.
- Click the error count in the upper-right corner to see a drop-down list of all errors in the configurator. Click any entry in that drop-down list to immediately go to the error.
Auto-Complete
Use auto-complete on field/variable combo boxes to quickly find your value (e.g. field name). You don't need to scroll through a long list of choices: just type the first few characters of what you want to see a list of matching options.
Finding References and Declarations to Snap Variables
See the page describing Variables to learn more on defining a variable, finding where it is used, backtracking from its use back to the definition, and understanding its scope.
Introspection and Reflection
The Snap language you write has the ability to introspect (examine the configurator UI at run-time) and reflect (manipulate the UI at run-time). This means you can create incredibly dynamic interfaces for your user. For example:
- If the current user is an administrator, then loop through all the fields in the configurator. If any field is hidden, then un-hide it, and add the text " (hidden)" at the end of the label.
- Control the maximum and minimum values allowed in a field, based on what the user entered previously.
See this page for examples of introspection and reflection.