Zmiany

Skocz do: nawigacji, wyszukiwania

Introduction 3 - Glossary of basic Scratch 2.0 blocks

Dodane 13 472 bajty, 09:09, 7 lip 2015
/* Operators */
<b><p align="center">Scenarios dedicated to primary school learners, 4th - 6th grade (basic level) These materials have been developed by Ośrodek Edukacji Informatycznej i Zastosowań Komputerów (Centre for Information Technology Education and Application of Computers) in Warsaw as part of the “Mistrzowie Kodowania” (“Masters of Coding”). Programme funded by Samsung Electronics Polska, licensed under CC BY-SA “Attribution – Share Alike 3.0”.</p></b><br/>
== Glossary of basic Scratch 2.0 blocks ==
Scratch is a scripting, visual programming language. We use it to build scripts by putting together blocks representing commands, control instructions, expressions, etc. The version 2.0 set of blocks is divided into 10 categories (there were 8 categories in version 1.4), blocks in each category are distinguished by a different colour. This glossary is not a description of all the blocks, only the most important ones as well as those used in scenarios of classes designed for students in grades four to six of primary schools developed as part of the “Masters of Coding” project. Version 2.0 introduces a very important '''More blocks''' category which allows users to define their own blocks. It is not described in this document, because the first eight scenarios do not expect users to create their own blocks. This category will be described in future scenarios. Each sprite and stage may have their own scripts. The set of blocks from which you can build scripts for a stage is slightly different than that used for sprites, for example the category '''Motion''' for the stage is empty, because the stage cannot be moved or rotated. First, we will discuss various types of blocks for sprites, and then basic information about blocks available for the stage will be provided.<br />
===Motion===
[[Plik:M_3_1.JPG|center]]
The category '''Motion ''' groups sprite movement blocks, used for their movement, rotation and reading current data related to a sprite’s location. These are very often used basic blocks. Below is a description of all the blocks in this category.
[[Plik:M_3_2.JPG]]
[[Plik:M_3_23.JPG]]
==Looks==
[[Plik:M_3_24.JPG|center]]
   [[Plik:M_3_24.JPG]] The '''Looks ''' category is a collection of sprite appearance blocks concerning costume, size, visibility, etc. Some of these blocks are used very often. Below is a description of most blocks in this category.
[[Plik:M_3_25.JPG]]
For a limited time displays in a speech bubble the text shown in the edit box. This means stopping the script execution for a specified number of seconds. A variable can also be dragged into the edit box or an expression can be built in it – often to connect the displayed information we use the '''join ''' block.
'''Example:'''
[[Plik:M_3_26.JPG]]
Displays in a speech bubble the text shown in the edit box and does not stop the script execution. Consequently, further instructions are executed, which might cause the bubble’s quick disappearance. A variable can also dragged into the edit box or an expression can be built in it – often to connect the displayed information we use the '''join ''' block.
'''Example:'''
[[Plik:M_3_27.JPG]]
For a limited time displays in a thought bubble the text shown in the edit box. This means stopping the script execution for a specified number of seconds. It works in the same way as the '''say ''' command, but a different kind of information is displayed. A variable can also be dragged into the edit box or an expression can be built in it – often to connect the displayed information we use the '''join ''' block.
'''Example:'''
[[Plik:M_3_28.JPG]]
Displays in a thought bubble the text shown in the edit box and does not stop the script execution. Consequently, further instructions are executed, which might cause the information’s quick disappearance. It works in the same way as the '''say ''' command, it is just a different kind of bubble. A variable can also be dragged into the edit box or an expression can be built in it – often to connect the displayed information we use the '''join ''' block.
'''Example:'''
[[Plik:M_3_39.JPG]]
Name of the currently displayed background. It can be used as an argument in expressions.
Checking the checkbox on the left displays the background name on the stage.
[[Plik:M_3_41.JPG|center]]
     ==Sounds==
[[Plik:M_3_42.JPG|center]]
[[Plik:M_3_45.JPG]]
Stops all currently played sounds.       
==Pen==
[[Plik:M_3_46.JPG|center]]
[[Plik:M_3_58.JPG]]
 
==Data==
[[Plik:M_3_59.JPG|centre]]
Hides the display of the value of the variable on the stage. It works is the same way as when we edit the checkbox of the variable name to disable it.
 
==Events==
 
[[Plik:M_3_70.JPG|center]]
 
The '''Events''' category includes blocks which start scripts reacting to specific events (e.g. clicking a sprite with the mouse, pressing a key on the keyboard) and related to message support (self-generating events in the programme). Below is a description of almost all the blocks in this category.
 
[[Plik:M_3_71.JPG]]
 
The basic block. It starts the majority of scripts. Scripts are run when we click the green flag on the screen – start the programme.
'''Example:'''
 
[[Plik:M_3_72.JPG]]
 
Runs the script after pressing a specific key on the keyboard. We select a key from a drop-down list.
 
'''Examlple:'''
 
[[Plik:M_3_73.JPG]]
 
The block runs the script when we left-click the sprite.
 
'''Example:'''
 
[[Plik:M_3_74.JPG]]
 
The block runs the script when a change of background occurs. The background name can be selected from a drop-down list. The script will be started when the background becomes the current one (displayed on the stage).
 
'''Example:'''
 
[[Plik:M_3_75.JPG]]
 
The block starts the script when a message of the specified name selected from the drop-down list is broadcast. We define the message in the '''broadcast message''' block. Broadcasting and receiving messages enables communication between sprites as well as the stage. In this way a sprite can run the script of another sprite.
 
'''Example:'''
 
[[Plik:M_3_76.JPG]]
 
This block allows us to define and broadcast a message. We can choose the message name from the drop-down list or define a new message using the '''new message...''' option available when we expand the list.
 
[[Plik:M_3_77.JPG]]
 
A dialog box will be displayed then, in which we enter the name of the new message.
 
[[Plik:M_3_78.JPG|center]]
 
After the message has been broadcast (this block has been executed), scripts which start with '''when I receive ''message name''''' blocks are automatically triggered. The script broadcasting the message is continued simultaneously. Example: See the description of the command '''when I receive'''.
 
[[Plik:M_3_79.JPG]]
 
Works in the same way as the block '''broadcast ''message name''''' (see the description of that command). The difference is that the operation of the script in which the message was broadcast is paused until the end of the operation of all the scripts receiving this message.
 
==Control==
 
[[Plik:M_3_80.JPG|center]]
 
The '''Control''' category contains very important blocks – equivalent to instructions controlling programming languages (loops, conditional instructions). Below is a description of all the blocks in this category except for sprite cloning.
 
[[Plik:M_3_81.JPG]]
 
This block stops the script execution for a specified time. The default value can be edited.
 
'''Example:'''
 
[[Plik:M_3_82.JPG]]
 
The block will repeat a set of instructions a specified number of times. The default number of repetitions can be edited.
 
'''Example:'''
 
[[Plik:M_3_83.JPG]]
 
The block will repeat a set of instructions forever, until the interrupting button – the red circle – is pressed. If the script with the '''forever''' block is to stop by itself, a conditional instruction should be used inside it and the '''stop''' block.
 
[[Plik:M_3_84.JPG]]
 
A conditional instruction block; a set of instructions will be executed once if a logical condition inserted after the word '''if''' is true. Conditions are built with the use of blocks of the '''Sensors''' and '''Operators''' categories.
 
'''Example:'''
 
[[Plik:M_3_85.JPG]]
 
A conditional instruction block; a set of instructions will be executed between the words '''then''' and '''otherwise''' if a logical condition inserted after the word '''if''' is true. Otherwise, the set of instructions following the word '''otherwise''' is executed. Conditions are built with the use of blocks of the '''Sensors''' and '''Operators''' categories.
 
'''Example:'''
 
[[Plik:M_3_86.JPG]]
 
Suspends the script execution until the logical condition is fulfilled. Conditions are built with the use of blocks of the '''Sensors''' and '''Operators''' categories.
 
'''Example:'''
 
[[Plik:M_3_87.JPG]]
 
The block will repeat a set of instructions until the logical condition is fulfilled. Conditions are built with the use of blocks of the '''Sensors''' and '''Operators''' categories.
 
'''Example:'''
 
[[Plik:M_3_88.JPG]]
 
Stops the execution of a script or scripts. From the drop-down list we can select: stop the script in which a block has been placed ('''this script'''), stop all scripts of all sprites and scenes ('''all''') or stop other scripts of the sprite with the exception of the script in which this block was started ('''sprite’s other scripts'''). Examples: see the description of the blocks '''forever''' and '''if'''.
 
==Sensing==
 
[[Plik:M_3_89.JPG|center]]
 
The '''Sensing''' category includes blocks related to the recognition of different situations that occur on the stage concerning, among others, sprites and the mouse, blocks to pull data from the keyboard, and blocks associated with the timer, date and camera. Below is a description of most blocks in this category, except for the camera operation and date blocks.
 
[[Plik:M_3_90.JPG]]
 
Checks if the sprite is touching the item selected from the drop-down list. This can be any other sprite, the mouse cursor or the edge of the stage. This block is used most often in conjunction with one of the following blocks: '''if, repeat until, wait until'''.
 
'''Example:'''
 
[[Plik:M_3_91.JPG]]
 
Checks if the sprite is touching a specified colour on the stage. To select a colour we should click the mouse in the box with the colour in the block, and then select the colour from the available colours using the mouse cursor. This block is used most often in conjunction with one of the following blocks: '''if, repeat until, wait until'''.
 
'''Example:'''
 
[[Plik:M_3_92.JPG]]
 
Checks if the selected sprite character colour is touching a specified colour on the stage. To select a colour we should click the mouse in the box with the colour in the block, and then select the colour from the available colours using the cursor. This block is used most often in conjunction with one of the following blocks: '''if, repeat until, wait until'''.
 
'''Example:'''
 
[[Plik:M_3_93.JPG]]
 
[[Plik:M_3_94.JPG]]
 
The current distance of the sprite from an item selected from the drop-down list – mouse cursor or another sprite. It can be used as an argument in expressions. The distance is measured from the centre of the sprite – we can set it by editing the costume.
 
'''Example:'''
 
[[Plik:M_3_95.JPG]]
 
Displays in a bubble the text entered in the block box, as well as a window with an edit box on the stage. It waits for input of data in the edit field and confirmation by pressing Enter or clicking in the edit box. The information entered by means of the keyboard is available in scripts with the use of the block '''answer'''.
 
'''Example:'''
 
[[Plik:M_3_96.JPG]]
 
 
The answer provided by the user, as the result of the block '''Ask and wait'''. It can be used as an argument in expressions. Checking the checkbox on the left displays the answer provided on the stage. Example: See the description of the '''Ask and wait''' block.
 
[[Plik:M_3_97.JPG]]
 
Checks if the key selected from the drop-down list has been pressed. This block is used most often in conjunction with one of the following blocks: '''if, repeat until, wait until'''.
 
'''Example:'''
 
[[Plik:M_3_98.JPG]]
 
Checks if the left mouse button has been pressed. This block is used most often in conjunction with one of the following blocks: '''if, repeat until, wait until'''.
 
'''Example:'''
 
[[Plik:M_3_99.JPG]]
 
The current value of this x and y coordinate of this mouse cursor. They can be used as an argument in expressions. These coordinates are also displayed below the lower right hand corner of the stage.
 
'''Example:'''
 
[[Plik:M_3_100.JPG]]
 
Current time in seconds since the last click of the green flag or execution of the block '''reset timer'''. It can be used as an argument in expressions. Checking the checkbox on the left displays the time on the stage.
 
'''Example:'''
 
[[Plik:M_3_101.JPG]]
 
Resets the timer count. The values provided by the timer block will be counted from zero again.
 
'''Example:'''
 
[[Plik:M_3_102.JPG]]
 
The current value selected in the first drop-down list, pertaining to the sprite selected from the second list or the stage. We can select the x or y coordinate, direction, costume number, name or size. For the stage we can choose the number or the name of the background. The returned value can be used in expressions.
 
'''Example:'''
 
[[Plik:M_3_103.JPG]]
 
 
==Operators==
 
[[Plik:M_3_104.JPG|center]]
 
The category of '''Operators''' groups blocks of basic arithmetic operations, logical operations and various functions (both arithmetic and on texts). All blocks in this category are used as arguments for other blocks. Below is a description of most blocks in this category.
 
[[Plik:M_3_105.JPG]]
 
Blocks of the four basic arithmetic operations (addition, subtraction, multiplication, division). In the edit boxes arguments should be provided (which may be manually entered numbers, the value of a variable or the result of another action, so blocks can be embedded). A built arithmetic expression should be used as an argument for another block, e.g. to determine the value of a variable or a logical expression.
 
'''Example:'''
 
[[Plik:M_3_106.JPG]]
 
Draws a number from a specified range. In the edit box we should specify the lower and upper range of the random number to be picked. The block should be used as an argument for another block.
 
'''Example:'''
 
[[Plik:M_3_107.JPG]]
 
[[Plik:M_3_108.JPG]]
 
Comparison blocks (less than, equal to, greater than). In the edit boxes we should specify values to be compared. We can enter specific values in the edit fields, most often one of the arguments is the value of a variable or a value read with the use of another block (e.g. a coordinate of a sprite’s position on the stage). This block is used most often in the following instructions: '''if, repeat until, wait until'''.
 
'''Example:'''
 
[[Plik:M_3_109.JPG]]
 
The blocks used to build complex logical expressions (conjunction – both conditions are true, alternative – one of the conditions is true, negation – contradiction). Insert the matching blocks returning Boolean values (true or false) in argument boxes. Blocks are used most often in the following instructions: '''if, repeat until, wait until'''.
'''Example:'''
 
[[Plik:M_3_110.JPG]]
 
The block is used to connect two strings of text into one. Usually one of the arguments is the entered text, and the other a value returned by another block. The block is often used as an argument in the '''say''' and '''think''' blocks.
 
'''Example:'''
 
[[Plik:M_3_111.JPG]]
 
The value is the remainder of the division of the first argument by the second. The block is often used as an argument in arithmetic and logical operations.
 
'''Example:'''
 
[[Plik:M_3_112.JPG]]
 
The value is the argument rounded off to the nearest integer – according to rounding rules, i.e. 0.5 and more is rounded up, otherwise down. The block is often used as an argument in other blocks.
 
'''Example:'''
 
[[Plik:M_3_113.JPG]]
 
The value is the result of the function selected from the drop-down list for the argument specified in the edit box. From the drop-down list we can select the following functions:
[[Plik:M_3_114.JPG]]
 
The block is often used as an argument in other blocks. Functions such as '''floor''' (always round down) and '''ceiling''' (always round up) may require explanation.
 
'''Example:'''
 
[[Plik:M_3_115.JPG]]
 
==Stage blocks==
 
[[Plik:M_3_116.JPG|center]]
 
The stage, like sprites, can have its own scripts. To create scripts for the stage we need to select it as the active object in the bottom right corner of the screen – the area for managing sprites and the stage. The choice of available blocks will change then – many of them apply only to sprites and may not be used in stage scripts. Differences are described below.
 
1. The '''Motion''' category
 
There is no block in this category, the stage cannot be moved or rotated.
 
 
2. The '''Looks''' category
Most changes are in this category. The stage can have multiple backgrounds, just like a sprite can have multiple costumes. There are blocks associated with the change of background and information about the selected background. The most important of these are the following:
 
[[Plik:M_3_117.JPG]]
 
 
3. The '''Sounds''' category
The blocks are the same, but when we play audio files they relate to the sounds assigned to the stage in the '''Sounds''' tab.
 
4. The '''Pen''' category
In this category, there is only one block for the stage – '''clear'''.
 
 
5. The '''Data''' category
 
The same as for sprites. The only difference is that we can only create variables available for all sprites.
 
 
6. The '''Events''' category
The same blocks as for sprites.
 
7. The '''Control''' category
The same blocks as for sprites.
 
8. The '''Sensing''' category
 
The same blocks as for sprites. There are no blocks for sprites interacting with other objects and colours ('''is touching, is touching the colour, the colour is touching the colour, distance from''')
 
9. The category '''Events'''
 
The same blocks as for sprites.
223
edycje