Programming with the Blocks Editor

Code the behaviour of the app.

Step 1

To start programming the behaviour of the app, go to the Blocks editor.

From the Blocks palette, click the Button1 drawer to open it. Drag and drop the when Button1.Click block onto the Viewer.

The yellow blocks are called event handler blocks. The event handler block tells the phone what to do when certain things happen, for example, when a button has been pressed.

Step 2

  • Click the Sound1 drawer
  • Drag out the call Sound1.Play block 
  • Snap it to the "do" section of the when Button1.Click block

The blocks snap together like puzzle pieces and you can hear a clicking sound when they connect.

You can delete a block by dragging it to the trashcan at the bottom.

The purple blocks are called command blocks, which are placed in the body of event handlers. Command blocks tell the components what to do. When an event handler starts, it runs the commands in its body. For example, when a button is pressed, a sound is played. 

Step 3

Are you ready to test your code? Try it!

Press the kitty button on your phone and hear it meow. Congratulations, you’ve just built your first app!

Step 4

Challenge: Make the kitty purrrrr!

The challenge is to program the phone to vibrate when Button1 is pressed. 

Tip: Go to the Blocks palette and click the Sound1 drawer. Choose a block that will make the phone vibrate. 

Step 5

The call Sound1.Vibrate block has an open slot, which means you need to plug something into it. Here, we want to control the length of the vibration. To make the phone vibrate for half a second, we need to plug in a value of 500 milliseconds.

  • Click the Math drawer
  • Drag out the number block
  • Place it in the empty slot of the call Sound1.Vibrate block
  • Click the number “0” and change it to “500”

Step 6

Test your code: the phone should vibrate and play the sound when you pet the kitty!