User Tools

Site Tools


starting:scratch2gp

# Scratch to GP

This section is for Scratchers trying out GP. It is based on this [original article](http://simplesi.net/scratch-to-gp/ “SimpleSi Article”) by SimpleSi.

Note: I'm using bold to indicate GP words/methods and *italics* to show *Scratch* words/methods.

Although GP and *Scratch* have a lot in common, there are some key differences between them and some things in GP look the same as *Scratch* actually behave differently.

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 here

1st Impressions The screen is not as cute and cuddly as Scratch but very similar.

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 sprite/class 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.

And with your sprite/class you can draw your own costume using the blocks in the Drawing and Pixels categories 🙂

There is a simple example of building a little project here

Getting Started Lets 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

No say for [ ] seconds block in GP

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

These for loops are used a lot in most programs (a lot of us thought Scratch should have it as well) as it saves a LOT of work 🙂

The variable i only exists as a temporary variable inside of the loop and is called a loop counter or loop index. You can right-click on it and give it nice name if you want 🙂

Moving a sprite/class around Major difference to do with movement is direction:

Scratch defines pointing up as direction 0, GP defines pointing right as 0

Scratch defines turning clockwise as an increase in direction, GP defines it as a decrease

Scratch GP

My initial gut feeling, is that should be a “use Scratch directions” block for beginners to GP but make it needed at the top of any script block that needs to use it. This way, Scratchers could stick with their world co-ordinate view but makes them work for it – eventually they’d stop using it – consider it like stabilisers on a bicycle 🙂

Control Loops

There is no repeat until block in GP – it has been replaced by while

Consider these two scripts

Scratch GP

So in Scratch repeat until will loop the loop until something becomes true but in GP the while will loop the 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

So you have to change count > 10 to shared count < 11 (or shared count ⇐ 10 [ ⇐ means less than or equal to ]

Forever

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
This will do same as above but is “better” GP way of doing it.  The while is always true and the wait waits for the screen to refresh
          	Fastest way to loop forever without waiting for screen refreshes

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.

One major change is that there is no actual Stage (Scratch 1.4) or Background (Scratch 2). So if you want a background image you create a big costume (GP screen size is 800 x 600 unlike Scratch’s 480×360) and just don’t move it around

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.

I have 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. I believe the Scratch Creative Commons Attribution-ShareAlike 2.0 license allows them to be used in GP but if anyone knows differently, please let me know

Other notable differences 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

There is no touching colour or touching edge 🙁 You can only detect touching a class or the mouse) There are complex ways around this but much easier/better to just re-think approaches to coding.

## Screen Layout The screen is not as cute and cuddly as *Scratch* but very similar.

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 <span style=“color:blue”>classes</span> and <span style=“color:blue”>instances</span> – just don’t worry about these names for the moment and treat them as being same as <span style=“color:orange”>sprites</span> 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 mistake, then you can easily get rid of them by pressing Clear button on the right)

There are only 2 inbuilt sprite/class 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.

And with your sprite/class you can draw your own costume using the blocks in the Drawing and Pixels categories

There is a simple example of building a little project here

Getting Started Lets 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

No say for [ ] seconds block in GP

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

These for loops are used a lot in most programs as it saves a LOT of work 🙂

The variable i only exists as a temporary variable inside of the loop and is called a loop counter or loop index. You can right-click on it and give it nice name if you want 🙂

Moving a sprite/class around Major difference to do with movement is direction:

Scratch defines pointing up as direction 0, GP defines pointing right as 0

Scratch defines turning clockwise as an increase in direction, GP defines it as a decrease

Scratch GP

Control Loops

There is no repeat until block in GP – it has been replaced by while

Consider these two scripts

Scratch GP

So in Scratch repeat until will loop the loop until something becomes true but in GP the while will loop the 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

So you have to change count > 10 to shared count < 11 (or shared count ⇐ 10 [ ⇐ means less than or equal to ]

Forever

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
This will do same as above but is “better” GP way of doing it.  The while is always true and the wait waits for the screen to refresh
          	Fastest way to loop forever without waiting for screen refreshes

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.

One major change is that there is no actual Stage (Scratch 1.4) or Background (Scratch 2). So if you want a background image you create a big costume and just don’t move it around Note GP screen size is 800 x 600 unlike Scratch’s 480×360

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.

I have 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. I believe the Scratch Creative Commons Attribution-ShareAlike 2.0 license allows them to be used in GP but if anyone knows differently, please let me know

Other notable differences 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

There is no touching colour or touching edge. You can only detect touching a class or the mouse) There are ways around this but much easier/better to just re-think approaches to coding.

starting/scratch2gp.txt · Last modified: 2017/09/30 09:03 (external edit)