Do you remember the last time you held a school bag? People all over the
world know why it was invented. We use it to carry things like books or
notebooks from one place to another. If you're wondering what the variable
meaning is, you can imagine it as a school bag. It's like a container or a
place where you can store your data.
Let's use our buddy Franky to show you how to deal with variables in Scratch.
Go to Costumes and copy the franky-mouse costume. We can call
the new one franky-mouse-mouth.
Now we need to add new variable in Scratch. Let’s go to
Code section and click Variables button. In variables area
we need to click Make a Variable button to add new one. We can name
it clicksCounter. We will use it to track the number of clicks on
Franky.
Our new variable clicksCounter has been added to the variables
section. Now we can take advantange of it. Let’s drag and drop first
code actions that will initialize our stage when we start the
application. Our goal is to reset clicksVariable to 0 each time
when we start the program.
Now it's time for the main part of the program. We would like to
increment the clicksCounter value by 1 each time Franky is clicked.
Additionally, we want to switch costumes to show that Franky is talking
to us. Note that we display the current value of our variable before we
return to the default costume.
Here we have the final result.
Comments
Post a Comment