On this page:
1.1 Example
1.2 Grammar
1.3 Syntactic Forms
use
---...-
image
x
y
size
direction
on
variable
do
random
touches
turn
move
forward
change
wait
say
hush
hide
show
send
watch
forever
while
if
is
to
by
key
message
everyone

1 Textual Language

 #lang scratchy package: scratchy

Here’s a program for a fish that swims randomly:

1.1 Example

#lang scratchy
 
-------------------------------------
fish
 
image is @fish-image
 
do
 forever {
   wait 0.02
   forward by 2
   turn by (random 5) - 2
 }

The ---...- starts a sprite declaration, where the sprite is named fish. In addition, if the file name is "fish-land.rkt", then fish-land is defined as the land where fish starts.

1.2 Grammar

Here’s the grammar of this textual language (click on a keyword for more information):

 

prog

 ::= 

use* sprite*

 

use

 ::= 

use id

 

sprite

 ::= 

---...- id clause*

 

clause

 ::= 

image is expr

 

  |  

x is expr

 

  |  

y is expr

 

  |  

size is expr

 

  |  

direction is expr

 

  |  

on key key statement*

 

  |  

on string message statement*

 

  |  

variable id is expr

 

  |  

do statement*

 

expr

 ::= 

number  |  image  |  string

 

  |  

id

 

  |  

expr binary-op expr

 

  |  

unary-op expr

 

  |  

random expr

 

  |  

touches expr

 

  |  

( expr )

 

statement

 ::= 

move x by expr

 

  |  

move y by expr

 

  |  

move x to expr

 

  |  

move y to expr

 

  |  

turn by expr

 

  |  

turn to expr

 

  |  

forward by expr

 

  |  

change size by expr

 

  |  

change size to expr

 

  |  

wait expr

 

  |  

say expr

 

  |  

hush

 

  |  

hide

 

  |  

show

 

  |  

change image to expr

 

  |  

send expr to expr

 

  |  

send expr to everyone

 

  |  

watch expr

 

  |  

move to expr

 

  |  

forever { statement* }

 

  |  

while expr { statement* }

 

  |  

if expr { statement* }

 

  |  

id = expr

 

unary-op

 ::= 

-

 

  |  

+

 

binary-op

 ::= 

+  |  -  |  *  |  /  |  <  |  >  |  <=  |  >=  |  =

 

key

 ::= 

id  |  +  |  -  |  *  |  /  |  <  |  >  |  =

 

id

 ::= 

a letter (in a/A to z/Z) followed by letters, numbers, and _s

 

  |  

@ followed by a sequence of letters, numbers, _s, and -s

 

number

 ::= 

a decimal number

 

string

 ::= 

sequence of characters between "s

1.3 Syntactic Forms

syntax

use id

Imports the sprite, variable, and land name of a land defined in the file whose name matches id with a ".rkt" suffix.

syntax

---...-

Starts a sprite declaration. Any number of -s can appear, as long as there are at least three.

syntax

image is expr

Determines the initial image for a sprite.

syntax

x is expr

syntax

y is expr

Determines the initial placement of a sprite.

syntax

size is expr

Determines the initial size of a sprite, as a multiple of its image’s size.

syntax

direction is expr

Determines the initial direction of a sprite, in degrees where 0 is north, 90 is east, 180 is south, and 270 is west.

syntax

on key key statement*

on string message statement*
Declares actions to take when a key is pressed or a message is sent or broadcast.

syntax

variable id is expr

Declares a variable, which is visible in the whole land.

syntax

do statement*

Starts a concurrent task.

syntax

random expr

Generates a random number between 0 and one less than the integer produced by expr.

syntax

touches expr

Produces true if this sprite is touching the one named by expr.

syntax

turn by expr

turn to expr
Changes the sprite’s direction either by a number of degrees clockwise or to a number of degrees like direction.

syntax

move x by expr

move y by expr
move x to expr
move y to expr
move to expr
Changes the sprite’s x or y location either by a number of pixels left/up or to a number of pixels from the screen’s center. If neither x or y is indicated, the sprite instead moves to the specified land (keeping its relative position from the current land).

syntax

forward by expr

Moves the sprite in its current direction by the specified number of pixels.

syntax

change size by expr

change size to expr
change image to expr
Changes the sprite’s size either by an amount to add to its current size multiplier or to a multiple of its image’s size, or sets the sprite image to a new image.

syntax

wait expr

Pauses a task for the specified number of seconds.

syntax

say expr

Causes the sprite to have a speech bubble with the specified content.

syntax

hush

Removes the sprite’s speech bubble, if any.

syntax

hide

syntax

show

Hides or shows the sprite.

syntax

send expr to expr

send expr to everyone
Sends a message to a specific sprite or to all sprites in the land. A sprite can respond to the message using an on string message clause.

syntax

watch expr

Switches the Scratchy view to the specified land.

syntax

forever { statement* }

Repeats the statements forever.

syntax

while expr { statement* }

Repeats the statements as long as expr produces true.

syntax

if expr { statement* }

Performs the statements only if expr produces true.

syntax

is

syntax

to

syntax

by

syntax

key

syntax

message

syntax

everyone

Keywords that are combined with many others.