Show Me Your State

Show Me Your State

We’ve explicitly dealt with input now. In an example program chunk of the previous activity, we used the when ↑ key pressed block to detect our input, and then move your sprite upward. But what does upward mean?

We know what the output (the observed behavior) of upward is: when the computer executes its commands, it redraws the screen with the sprite 10 pixels above his previous location. How does the program know where to draw the updated Scratch and which direction to face him?

The computer needs to “remember” the sprite’s original location and orientation, its state, and update them with new ones—by accessing and modifying storage. Examine the following instructions; locate the attributes (of the Scratch sprite) we are changing:

We are changing the sprite’s direction attribute as indicated by the point in direction [0] block. However, we are also changing his location with the move [10] steps block. “10 steps” is not an attribute of a sprite—what attributes do you hypothesize indicate location?

Scratch uses the familiar x-y coordinate plane to indicate location. This means that each sprite has three attributes associated with it for location and orientation: direction, x position, and y position. You can view these attributes and their associated values by checking the following boxes in the Motion tab:

Try It Out!

Load your Scratch program from User input and interaction.

Experiment with location and orientation using the direction, x position, and y position blocks. Move your sprite around and observe how its state changes over time.

For a more detailed view of a sprite’s state, you can right-click the sprite in the sprite picker, and select “info.”