====== 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 [[https://gpblocks.org/run/gp.html|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 [[https://gpblocks.org/pdf/GP_Starter_SimplePaint.pdf|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 | | {{:starting:countto10.gif|}} | {{:starting:countoe-e1499352386506.png|}} | | Press Green flag | Press go button | So main differences were: When Green Flag click == when I receive go There is no {{:starting:scratch2gp:say2secs.gif|}} 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 | {{:starting:scratch2gp:gpcountto1e.png?nolink|}} | 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 {{:blocks:i.png|}} and give it nice name if you want ===== Moving a sprite/class around ===== TWO MAJOR DIFFERENCES BETWEEN //Scratch// AND **GP** - 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 ^ | {{:starting:scratch2gp:scdir.png|}} | {{:starting:scratch2gp:gpdir.png|}} | ==== Control ==== === Loops === There is no {{:starting:scratch2gp:scr_repeatuntil.gif|}} in GP – it has been replaced by {{:blocks:while.png|}} Consider these two scripts ^ Scratch ^ GP ^ | {{:starting:scratch2gp:scr_repuntil.gif|}} | {{:starting:gp_repuntil-e1499445036595.png|}} | 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 ^ | {{:starting:scratch2gp:scr_forevercount.gif|}} | {{:starting:scratch2gp:gp_animatecount.png|}} \\ This is direct replacement.\\ It will loop forever and wait for screen to\\ refresh between each loop so you\\ don’t get any flicker | | | {{:starting:scratch2gp:gp_whilewaitcount.png|}} \\ 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 ^ | {{:starting:scratch2gp:sct_if-1.gif|}} | {{:starting:scratch2gp:gp_if-1.png|}} | | {{:starting:scratch2gp:scr_ifelse.gif|}} | {{:starting:scratch2gp:gp_ifelse-4.png|}} | 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)