Data Representation

Every Scratch project needs a set of information about the characters in order to run properly. For example, we need to know the position of each character, the direction it is pointing, size, etc. In addition, programmers can create new information repositories to store other data such as the level at which we find ourselves, elapsed time, the rating, the lives, the rewards collected ...

If you get 1 point...

Each character of a Scratch project has a number of features, or attributes, that every moment of the project have value, and can be modified by programs. For example, a character has a certain size that can be modified by block 'resize for 10', making the character appear slightly larger. Following is the list of attributes that each character and blocks that can be used to modify:

Position:

                            move (10) steps

                            go to x:(0) y:(0)

                            glide (1) secs to x:(0) y:(0)

                            set x to (0)

                            set y to (0)

                            change x by (0)

                            change y by (0)
                        
Size:

                            change size by (10)

                            set size to (120)
                        
Orientation:

                            point in direction (90 v)

                            point towards [v]

                            turn cw (15) degrees

                            turn ccw (15) degrees
                        
Costume:

                            switch costume to [butterfly v]

                            next costume

                            change [color v] effect by (25)

                            set [color v] effect to (0)
                        
Visibility:

                            show

                            hide
                        

If you get 2 points...

In addition to modifying the attributes of the characters, programmers can use other mechanisms to store information on a Scratch project. One of these mechanisms are variables that can store a value to store different types of data that may need: at what level we are, how many lives you have left, how many points we, how is called the user ...

To create a variable you have to go to the category of data, click on 'Create a variable' and give a name. In the example shown below we have given the name 'Points' as use it to store the number of points you get our character.

                    when green flag clicked
                    set [Points v] to [0]
                    if <touching color [#0000FF]> then
                    change [Points v] by (1)
                

In the program of the top, we assign the number of points that we want the character has to the beginning of the game, in this case 0, for which we use the block 'fixing points at 0'. However in the program of the right, what we do is that when the character touches the blue color, that could be a target, you will add a point, for which we use the block 'change Points by 1'. In this case, the block 'change' would check the current value of the variable points would add 1: If set to 0, I add 1 and is now worth 1; when set to 1, I add 1 and is now worth 2 ...

If you get 3 points...

In addition to the variables, Scratch lets you use another data type to store project information: The lists. The lists can store more than one value at the same time, so they are ideal for storing rewards have been recovered by a character or set of names, raise a couple of examples.

To create a list, you have to go to the data category, click on 'Create a List' and give a name. In the example, we have named our 'Students' list:

                    when green flag clicked
                    delete (all v) of [Students v]
                    repeat (3)
                    ask [Introduce a student name] and wait
                    insert (answer) at (last v) of [Students v]
                

What have we done with this program? The first thing we do is, to start execution, delete all items from the list Students, to empty it completely and not appear elements of an previous project implementation. Then we ask three times the user to enter a name, and each name entered insert it in the last position in the list Students.
What we do with the list? We could, for example, use it to get a volunteer to carry out an exercise to the whiteboard. Look at the new instructions added to the program:

                    when green flag clicked
                    delete (all v) of [Students v]
                    repeat (3)
                    ask [Introduce a student name] and wait
                    insert (answer) at (last v) of [Students v]
                    end
                    say [Today's volunteer will be...] for (2) secs
                    say (item(pick random (1) to (3)) of [Students v]) for (2) secs
                

We generated a random number between 1 and 3, which are the elements in the list, we selected the element that occupies that position in the list. Sometimes we take the name that is in position 1, others that it is in position 2 and the other at 3.
Lists have many possibilities and many available operations ... you dare to investigate how they work?


If you get 4 points...

Using boolean logic is essential for effective data representation because it allows you to handle and evaluate multiple conditions simultaneously. This enables more precise and flexible decision-making in your Scratch project, improving how your code responds to various scenarios and data inputs.

These blocks can be:

                    <(value1) = (value2)>
                    <(value1) > (value2)>
                    <(condition1) and  (condition2)>
                    <(condition1) or  (condition2)>
                    <not (condition)>
                

An example of the use of these blocks is:

                    if << (score) > [10] > and <touching color [#FF0000]>> then
                        say [You win!] for (2) secs
                        else
                        if<< (score) < [10] > or <not <touching color [#FF0000]>>> then
                        say [Try again!] for (2) secs
                        end
                        end
                

By using these boolean logic blocks, you can create more complex and interactive elements in your Scratch project.