• No results found

2.3 Related Visual Game Generators

2.3.1 Scratch

Scratch [7] is the simplest of the three building-block VPEs. Scratch supports the creation of interactive stories, animations, games, music and art [6]. Figure 2.11 shows the Scratch main window. The main window is divided into five sections which we call drawer switcher, blocks drawer, script window, stage and stage/sprite

window. The building blocks in Scratch, which we will now call blocks for brevity,

Figure 2.11: A screenshot from Scratch [7] showing the main window

are grouped into eight categories. Blocks belonging to the same category share the same colour. Each block category is visually represented by a button labelled with the category’s name. Clicking a category button from the drawer switcher causes the blocks drawer to display blocks from the corresponding category. This setup is useful because it facilitates faster searching for the blocks; and it also makes the screen tidier by limiting the number of blocks appearing on the screen.

The blocks drawer contains instances of blocks that can be used to build programs. Each block instance in the blocks drawer is capable of generating an infinite number of replicas of itself, in theory. When a user drags a block from the blocks drawer, the block is duplicated; and the original block remains in the blocks drawer whereas the new copy can be dropped into the script window. When a block is dragged and dropped back into the blocks drawer, it is deleted.

The script window is where the script is crafted. Scratch maintains as many script windows as the numbers of sprites on the stage; however, only one script window is displayed at a time. A script window for a particular sprite can be displayed by selecting the corresponding sprite from the stage/sprite window.

Scratch supports event-driven programming through the four when blocks shown in Figure 2.12. A stack of blocks, whose top block is connected to a when block, is executed when the event stated in the when block occurs at runtime.

Figure 2.12: Scratch’s event blocks

These four when blocks also facilitate the specification of concurrent scripts. Fig- ure 2.13 shows an example of using when blocks to express concurrency. Since the play note and the play drum blocks are attached to separate instances of the when...key pressed block (each instance having the same parameter, namely, space), the play note and play drum blocks are executed concurrently when the user presses a space keyboard key at runtime.

Scratch also supports the definition and manipulation of variables and lists. Both variables and lists can be defined as global, in which case they are available in all script windows for the project. Variables and lists can also be defined as local, in which case they are only available in the script window for the sprite for which they are defined.

We observed the following weaknesses in the Scratch VPE:

1. Lack of support for modularity. Scratch does not implement any mechanism to fully support modular abstraction. There is, however, limited modularity which results from the isolation of scripts when the script uses more than one event block (when... block). This limited modularity cannot be used to im- plement abstraction. The lack of abstraction means the script for controlling animation is tightly coupled with the script controlling the high level logic of the games; thus the user is forced to reason about animation and game logic simultaneously;

2. Lack of a visual representation of constants. Scratch does not have a set of blocks representing various types of constants12. This means that con-

stant values have to be typed directly into the expressions in which they are required. Although blocks representing algebraic operators screen out non- numeric data, syntax errors13are still possible as demonstrated in Figure 2.14.

In the figure, the add...to... block inserts the string, “scratch”, into the empty list, list2. The item...of... block returns the first item of list2. The “mul- tiply” block multiplies 2 and the string “scratch”14. The say... block displays

the result of the multiplication in a sprite’s callout. Figure 2.15 shows the result of running the script;

3. Misleading implementation of lists. The add...to... block accepts variables representing lists in the first socket, meaning that a list can be inserted into another list. There is, however, no expression for extracting elements of a nested list;

12Scratch has only one block representing the two types of supported variables, namely numeric

and text.

13Scratch conveniently treats syntax errors as runtime errors, affecting only the computed

result.

Figure 2.14: A syntax error in Scratch: an attempt to multiply a number and a string

Figure 2.15: The syntax error in Figure 2.14 treated as a runtime error by Scratch

4. Representation technique shifts. Scratch lacks blocks for defining variables

and lists. Variables and lists are defined by using forms, which is a deviation from the building-block representation technique.