User Tools

Site Tools


starting:scratch2gp2

Using GP for Scratchers

In this tutorial GP concepts and words will be shown in bold, and Scratch concepts and words will be shown in italics

Running GP

It is available for Windows,Mac and Linux from https://gpblocks.org/

There is also a version running on a web server so it can be tried out without having to install anything

1st Impressions

The screen is different in layout to Scratch but has the same basic areas.

Top left are block categories – next is blocks within category – scripts go bottom left – the stage is on the right.

(GP draws a dotted line to sprites – just click show arrows at top right to switch this off)

Below the stage are the classes and instances – just don’t worry about these names for the moment and treat them as being same as sprites i.e if you want a new sprite – click on Classes +

(Instances + is like Scratch 2 cloning to create a copy of a sprite so just leave that alone for moment)

(If you do press Instances + by mistook, then you can easily get rid of them by pressing Clear button on the right)

There are only 2 inbuilt costumes – one called ship and another one called GP.

But you can load any .png type file by clicking on Images tab and selecting Add Images From File.

Instances only have one costume but you can modify it (or draw your own) using the blocks in the Drawing and Pixels categories

There is a simple example of building a little project here

Getting Started

Lets make a simple project in both Scratch and GP to count to 10

Scratch GP
Click variables – create a variable called count (for all sprites) Click variables – Add a shared variable called count
Scratch automatically shows a variable on stage so nothing to do Right click on shared (count) -select monitor- drag to stage
Build this script Build this script. The difference is go is equivalent of green flag and use black arrow on wait to change time to 1 second
Press Green flag Press go button

So main differences were:

When Green Flag click == when I receive go

There is no in GP so we always have to add in own own wait block

Now although we can write nearly
the exactly same code in GP compared to Scratch,
GP has far more programming tools so this
is the actual way of doing this in GP

These for loops are present in nearly all programming languages (Scratch being a notable exception) so they are well worth getting to know as it saves having to create a variable to keep track of the count and having to have a block to increase it inside of the loop.

Note: You can right-click on the and give it nice name if you want

Moving a sprite/class around

TWO MAJOR DIFFERENCES BETWEEN Scratch AND GP

  1. Scratch defines pointing up as direction 0, GP defines pointing right as 0
  1. Scratch defines turning clockwise as an increase in direction, GP defines it as a decrease
Scratch GP

Control

Loops

There is no in GP – it has been replaced by

Consider these two scripts

Scratch GP

So in Scratch repeat until will loop until something becomes true but in GP the while will loop while something is true

So in Scratch we are looping until the count is bigger than 10, in GP we loop while the count less than 11

Scratch GP

This is direct replacement.
It will loop forever and wait for screen to
refresh between each loop so you
don’t get any flicker

Alternatively, we could use a while loop
with an added wait at the end
which will work exactly the same way

If and If/Else

Scratch GP

GP uses one combined if block instead of Scratch’s two types. It can be changed from if to if/else by simply clicking on the black arrow

GPs if/elseif block is much more powerful than the simple example above and can save a lot of nested if statements which leads to your code being easier to read and debug

Graphics

GP has a lot in common with Scratch but some notable differences

The one thing that is the same is the Pen category that lets your draw over the screen just as in Scratch.

Stage/Background

There is no actual Stage (Scratch 1.4) or Background (Scratch 2).

But you can easily simulate this by creating a class with a big costume (GP screen size is 800 x 500 unlike Scratch’s 480×360) and just don’t move it around.

Costumes

GP only comes with 2 images (the Ship and the GP one) but you can load in any .png image and set the instances costume to it very easily.

Simon Walters has converted all the Scratch 1.4 images to .png and re-sized the background ones to be 800×500. The zipped file of these images is available here.

Other notable differences

Timer

The timer counts up in milliiseconds (thousanths of seconds) and there is no reset timer block. So you have to set a variable, say starttime, to timer value and then subtract the timer from your starttime and divide it by 1000 to get the time difference in seconds.

Touching

There is no touching colour or touching edge. You can only detect touching a class or the mouse)

starting/scratch2gp2.txt · Last modified: 2017/09/30 17:27 by simplesi