Pytch: Help

Editing and compiling

You write and edit your Python program in the left panel. Unlike Scratch, where changes take effect straight away, in Python you must compile your program first. In Pytch, this is done with the COMPILE button in the menu-bar at the top. Compiling can take several seconds for a complicated program. If there are errors in your program, a description of the problem will appear in the ‘Errors’ tab underneath the editor.

Running and stopping

Once your program compiles successfully, you can click on the stage and then use your program. Many projects will need the user to click the green flag (currently a rectangle), but not always. To stop all running scripts, hit the red stop button. The green flag and stop button are both below the stage.

Sprites

Each sprite in your project has its own Python class, which must be derived from the pytch.Sprite class. For example,

class Star(pytch.Sprite):
    # Code for Star goes here

Stage

Your project must have a class for the stage, which must be derived from the pytch.Stage class. For example,

class Stage(pytch.Stage):
    # Code for your stage goes here

Scripts

The Pytch equivalent of a script for a sprite is a method on that sprite. For example,

    @pytch.when_key_pressed('ArrowUp')
    def move_up(self):
        self.change_y_pos(10)

Here we see that a method decorator does the job of a Scratch hat block, and the method call self.change_y_pos(10) does the job of the change y by Scratch block.

Costumes

Your sprite must have at least one costume. These are given in a class attribute called Costumes, for example

class Player(pytch.Sprite):
    Costumes = {'python': ('pytch-images/python-logo.png', 25, 25)}
    # ... other code for Player ...

The Costumes attribute is a Python dictionary. Each key is the name of that costume, to be used in switch_costume() calls. The value is a tuple of three things:

See examples for how your program provides these pieces of information to Pytch. We have supplied a few sample costumes with this initial version; we intend to expand the collection in the future.

Sample costumes

For this initial release, these costumes are available:

Stage backdrops

Your Stage-derived class must have an attribute Backdrops of the same form as a Sprite’s Costumes attribute, for example

class Stage(pytch.Stage):
    Backdrops = {'pong': 'pytch-images/backdrop.png'}
    # ... other code for Stage ...

The image should 480 pixels wide and 360 high.

The current implementation only supports one backdrop, so its name (‘pong’ in the above example) is not used.

Sample backdrops

For this initial release, these backdrops are available:

Sounds

If you want to use sounds, your sprite must have a class attribute called Sounds, for example

class Player(pytch.Sprite):
    Sounds = {'pop': 'pytch-audio/pop.mp3'}
    # ... other code for Player ...

The Sounds attribute is a Python dictionary. Each key is the name of that sound, to be used in a start_sound() block. The value is a URL for the sound file. We have provided a handful of example sounds for this initial version.

See the examples for how this works.

Sample sounds

For this initial release, these sounds are available:

Equivalents to Scratch blocks

Apart from 'hat' blocks, Pytch provides equivalents to (some) Scratch blocks in three ways:

Methods on a Sprite

Methods on the stage

In future we hope to implement the various Stage-only blocks from Scratch, for example next_backdrop().

Functions within the pytch module

Scratch 'hat' blocks

Done via Python decorators. E.g.,

    @when_I_receive('Play_One_Point')
    def prepare_to_play(self):
        # ... do stuff ...

The available decorators are:

Final last pieces of a Pytch program

We are working on reducing the amount of boilerplate required, but currently there is still a small amount.

You must import the Pytch module at the top of your program, by writing

import pytch

After defining all your Sprite-derived classes, and your Stage-derived class, you must register them all with code along the lines of

pytch.register_stage_class(Stage)
pytch.register_sprite_class(Player)
pytch.register_sprite_class(Star)

and then the last line of your Python program should be

pytch.run()

to launch the project!

Errors

If there is an error in your Python program, this will be shown in the red-backed ‘Errors’ tab. Currently the error messages are given in their raw form; providing more useful messages is on the roadmap.

Multitasking

All scripts under hat blocks generally run to completion when that script is triggered, before the screen is updated. The exceptions are:

One consequence of this is that if you have a very complex piece of processing inside an event handler, your project might appear to have crashed. Try to keep things simple!

Privacy

No project code ever leaves your browser. Everything you create is stored locally.