Previous | Next

Interaction | Looping

Thusfar, we just created programs that created drawings on the TagTiles board. However, besides lighting cells on the TagTiles board, you typically want to add some interaction in an application. In this example, we wait for the user to put down an object on the TagTiles board, and then make that cell yellow.
//Right-click to download this code

import "tagtiles.esp"

main = (
  await (tagEvent down isYellowBlock); 
  drawShape (Cell lastTagCoord) yellow
)

Some new macros

Notice that we have used the macro await. This macros requires one parameter: the condition to wait for.

We specified the waiting condition using the tagEvent macro. This macro requires two parameters:

  1. The kind of event to wait for. In this case, we want to wait until the user put an tag down on the board. We specified this with the down macro, that does not take any parameters.
  2. Which tag to wait for. In this case, we want to wait for a yellow block, as indicated through isYellowBlock. This macro also does not take any parameters.

Another macro that you did not see before, is lastTagCoord. This macro does not take any parameters. It is defined as the most recent coordinate in which the user placed a tag.

What this program does

This program works as follows: first it will wait until the user puts down a yellow block somewhere. Then, the cell in which the user put down that object will turn yellow.

Waiting for interaction events

In the example, we wait until the user put down the object, but likewise, you can wait for up, or move. If you want your program to react on any kind of event, use anyTagEvent.

Further, we waited for a tag of a yellow block, but likewise, you can use e.g. isBlueBlock or isGreenBlock. If you want your program to react on any object, use anyTag.

Sequencing commands

Note how we have again combined the two commands using a semicolon. With the semicolon, we have created a sequence: the TagTiles board will first await the placement of a yellow object and when that is done it will light that cell in yellow. There are no more commands, so after this command, the program terminates.

Exercise

  • Alter the program such that whenever you put down the blue block, that cell turns blue.
  • Alter the program such that when you lift up the blue block from the board, that cell turns blue.

Looping

You may have noticed that when running this application you can only light one cell. If you want a cell to light up every time you place the yellow object on it, you can use loop.

//Right-click to download this code

import "tagtiles.esp"

main = (
   loop (
     await (tagEvent down isYellowBlock);
     drawShape (Cell lastTagCoord) yellow
   )
)
We put the two commands between the brackets after the word loop. This will cause those two commands to repeat continuously, as long as the application is running on the TagTiles board.

Now we have a basic drawing application: the user can draw yellow cells with the yellow tag!

Previous | Next

Serious Toys logo -  tangible inspiration without limitation