On this page:
1.1Example
1.2Grammar
use
x
y
on
do
say
if
is
to
by
key
top
up

1Textual LanguageπŸ”— i

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

1.1ExampleπŸ”— i

 
-------------------------------------
fish
 
imageis@fish-image
 
do
forever{
wait0.02
forwardby2
turnby(random5)-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.2GrammarπŸ”— i

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

prog

::=

use*sprite*

use

::=

use id

sprite

::=

---...-idclause*

clause

::=

image is expr

|

x is expr

|

y is expr

|

size is expr

|

direction is expr

|

on keykey statement*

|

on stringmessage statement*

|

variable idis expr

|

do statement*

expr

::=

number|image|string

|

id

|

exprbinary-opexpr

|

unary-opexpr

|

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 exprto expr

|

send exprto 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.3Syntactic FormsπŸ”— i

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 keykey statement*

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

syntax

variable idis 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 exprto expr

send exprto 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 stringmessage 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.

top
up

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /