Searching and Typeblocking

In this tutorial we we will go over the basics of two new features in Preview 3, which allow us to search for blocks and create block code with the keyboard.


Block languages make it easier for us to program because we don't have to remember the names of the commands or what types of arguments they take. All we have to do is find the command we want in the block factory, drag it out, and connect it in the right spot. The problem is that sometimes we can't remember which category the block we want is in. Another tricky problem is when we've been working on a really large project for a while with dozens and dozens of blocks, and we can't remember where we put parts of our program. Sure, the Minimap helps us find our way around, but we often wished that we could just search for the block we're looking for, the same way we use Google to find a web site quickly instead of hunting through our bookmarks. Now, we can, using the handy search bar in the corner of the Blocks view shown to the right.

As you type into the search bar, StarLogoBlocks begins to light up, highlighting every block bright yellow that contains what you typed in its name. Below, I typed "set." Both the "setx" and the "set height" blocks contain the letters "set," so they light up, both in the workspace and in the factory. You'll also notice yellow splotches on the Minimap that show where other "..set.." blocks are that we can't see. For example, the tall one in the middle is a "Setup" block.

Also, notice that some of the categories lit up yellow as well: Interface, Movement, Colors, Control, and Traits. That's because those are all of the categories that contain blocks that have "set" in their name. So, now, if you ever forget where the "setx" block is, just search for it, and the Movement category will glow yellow!

To make it even easier to use search, we added a few extra menu items and keyboard shortcuts. "Find Blocks" is nothing special; it just moves your cursor to the search bar so you can start typing your search term. After you type your search term, and a bunch of blocks on the workspace turn yellow, you can use "Find Again" or "Find Previous" to jump to the next or previous block in the search results. Actually, "jumping" is not the right word; it's more like you fly to the next block. The workspace glides from wherever you were looking over to the next block so it becomes the center of your view.

Finally, "Find Related Blocks" is for those times when you're looking at a procedure and want to find all the places where it gets called, or you are using a variable and wish you could find the variable declaration block so you can rename it. "Find Related Blocks" searches the workspace for blocks with the same name as the last block you clicked on. Since procedure call and definition blocks have the same name, and since variable declaration, getter, and setter blocks all have the same root name, Find Related Blocks helps you find all those similar blocks instantly.


Typeblocking is our word for using the keyboard to type out blocks instead of dragging them onto the factory with a mouse. For some users who prefer to use the keyboard, mastering Typeblocking may allow for much faster StarLogo model development. To enable Typeblocking, choose "Keyboard moves blocks" from the "Options" menu. Note that if you want to resume using the keyboard to move the camera in Spaceland or control models with keyboard input blocks, you will need to choose the correct setting from the Options menu. Choosing among these options will be easier in a future version.

Just as when typewriting, there is a cursor for Typeblocking to show you which block currently has focus and where the next typed block will appear. The block cursor highlights the current block with focus in blue. For example, drag the "forward" block onto the workspace. It will appear highlighted in blue. Next, drag out the "right" block and attach it to the forward block. Notice that focus transferred to the "right" block. You can move the cursor by clicking on blocks or by using the tab or arrow keys to shift focus within a single stack of blocks.

To place additional blocks on the stack, simply begin typing the name of the block. For example, if you type "heading," then you will see the autocomplete list appear with your current query in red and the list of all blocks that may be connected to the block with focus. Here, the "heading" and "heading of," blocks can connect to the "right" block's number port, and the "set heading" block can connect to its next command port. You can use the arrow keys or the mouse to select the block from the list that you want to appear and then press enter or double-click to cause that block to appear.

In this example, we chose the "heading" block, and that block flew out and connected itself to the number port appropriately. Now, if we give focus back to the "right" block and type "heading" again, only the "set heading" block appears in the list because the number port is full and cannot accept a new block.

In addition to using the autocomplete list to type blocks that fit into the block with focus, Typeblocking is further optimized for arithmetic expressions. If a block such as the "right" block has an empty number port, simply type the number you want, and a number block of that value will connect itself automatically. When a number block has focus, it is simple to extend the expression using simple binary operators to add, subtract, multiply, or divide other numbers.

Finally, in addition to supporting the connection of new blocks, Typeblocking includes other keyboard shortcuts for making StarLogo TNG more efficient to use with a keyboard. For example, Command-+ (or Control-+ on Windows) zooms into the block workspace, while Command-(minus sign) zooms out and Command-0 returns the workspace to its default zoom level. Additionally, when a procedure block has focus, Command-Enter toggles the rolled up state of the procedure. For any other block, Command-Enter causes StarLogo TNG to execute that block as though it had been double-clicked on. If a block is editable, pressing enter (without holding down the Command key) toggles edit mode for the block to make it easy to change the block's value.




More Information
Developer Blog

MIT Teacher Education Program