Have you ever wanted to create a fun and interactive program using Scratch? Some programs always do the same thing, but others can change and react differently each time you use them. To make these dynamic programs, we use something called conditional statements. These are special instructions that tell the program what to do in different situations.
Imagine you have a game where you control a fish with your mouse. What if you want something special to happen when your fish touches another character, like a pufferfish? In Scratch, you can find conditional statement blocks under the Control category. These blocks help you set rules like “do this until something is true” or “if something is true, then do this.”
For our fish game, we’ll use a block called “wait until”. In the Sensing category, there’s a block called “touching mouse-pointer”. You can use this block to check if your fish is touching the pufferfish. Conditional statements can be either true or false. If the fish and pufferfish aren’t touching, it reports “false.” If they are touching, it reports “true.” These blocks are called Boolean blocks and have a special shape like an elongated hexagon.
Let’s see how “wait until” and “repeat until” blocks work. If we use “wait until,” the program waits for the fish to touch the pufferfish before playing a sound. With “repeat until,” the sound keeps playing until the fish touches the pufferfish. It’s like the opposite effect!
Now, let’s make the fish show a different costume and think “Ouch” when it touches the pufferfish. Did you notice that “Ouch” only appears once? That’s because the program checks the condition just once. If we put this code inside a “forever” loop, the program keeps checking, and “Ouch” appears every time the fish touches the pufferfish.
What if we want the fish to switch back to its original costume when it’s not touching the pufferfish? If we put the costume-switching block inside the loop, the program quickly switches back and forth. Adding a small wait before checking can help us see the change more clearly.
There are many ways to achieve the same result. Instead of “wait until,” you could use an “if then” or “if then else” statement. By adjusting the “think” block, you can make the costume switch immediately when the fish stops touching the pufferfish.
What else can you try or add to your project? Experiment and have fun! In our next lesson, we’ll add some code to the pufferfish and learn how to fix problems with conditional statements. We’ll also explore more complex scripts by nesting conditional statements.
Use Scratch to create a simple game where you control a fish with your mouse. Add a pufferfish character and use conditional statements to make something special happen when your fish touches the pufferfish. Experiment with different actions like playing a sound or changing the fish’s costume.
Try using both “wait until” and “repeat until” blocks in your Scratch project. Observe how they behave differently. Can you make the fish say “Ouch” every time it touches the pufferfish? Use a “forever” loop to keep checking the condition.
Design a Scratch project where your fish switches costumes when it touches the pufferfish. Add a small wait before checking the condition again to see the costume change more clearly. Can you make the fish switch back to its original costume when it’s not touching the pufferfish?
Use “if then” and “if then else” blocks in your Scratch project to create different outcomes. For example, make the fish think “Ouch” only when touching the pufferfish and switch costumes immediately when it stops touching. Experiment with different scenarios and see what you can create.
Share your Scratch project with a classmate and discuss the different conditional statements you used. Explain how they work and what happens in your game. Ask your classmate for feedback and see if they have any suggestions for improvement or new ideas to try.
Sure! Here’s a sanitized version of the YouTube transcript:
—
Have you ever wanted to create an interactive Scratch program or one that offers multiple outcomes? Some Scratch programs are static, meaning the outcome is fixed and the same thing happens each time. Others are dynamic, capable of action or change each time they are run. To create dynamic programs, programmers can use conditional statement blocks to give instructions on how the program should respond in different circumstances.
For example, I have a program where a fish can be controlled by my mouse. What if I wanted a unique action to take place if the fish touches another sprite, like a pufferfish? Under the Control category in Scratch, I can find several conditional statement blocks that allow me to adjust the program based on specific conditions, such as “until something is true or false” or “if something is true or false, then.” For this fish game, I’m going to use a “wait until” block.
Under the Sensing category, I’ll grab the “touching mouse-pointer” block and use the dropdown menu to select my pufferfish sprite. Conditional statements can be true or false. If the sprites aren’t touching, this block will report “false.” If they are touching, it will report “true.” There are many conditions in Scratch that you can choose from to complete a conditional statement. Blocks that report “true” or “false” values are known as Boolean blocks, identifiable by their elongated hexagonal shape.
To see the difference between the “wait until” and “repeat until” conditional statement blocks, I’m going to have it play a sound. Let’s run the code and see what happens. With “wait until,” it waited until my fish was touching the pufferfish, and then the sound played. Now, let’s try the “repeat until” block and observe the difference. Notice that the opposite effect happened; it repeated the sound until the condition was true, meaning until the fish was touching the pufferfish.
I’m going to wait until the fish is touching the pufferfish, and then show one costume to start and another if they touch. I’ll also have the fish think “Ouch” when they touch. Did you notice that, once the fish touched the pufferfish, if they touched again, you don’t see “Ouch” again? That’s because the program is only checking if this condition is true once. If I put this code stack inside a “forever” loop, let’s see the difference. Now, each time the fish touches the pufferfish, you’ll see “Ouch!” because it’s continually checking to see if the condition (touching pufferfish) is true.
What if I want the sprite to switch back to the initial costume when it isn’t touching the pufferfish? Notice the difference when I have the block to switch back to the initial fish costume inside the loop versus outside the loop. When inside the loop, the program is constantly switching to the original costume, but then immediately checking to see if they are touching. If so, it shows the “Ouch” costume. It checks so quickly that our eyes don’t see the switch. But if I add a small wait just before the check, you can see what I mean.
There are often multiple solutions to accomplish the same goal. For instance, I could use an “if then” or “if then else” statement instead of a “wait until” conditional statement here. If I make a small adjustment to the “think” block in this “if then else” statement to remove the time, notice if I move my mouse away quickly, I can get the costume to switch immediately after they stop touching.
What else could you try or add? Tinker and experiment! In our next video, we’ll add some code to the pufferfish, too, and practice debugging conditional statements and making more complex scripts by nesting conditional statements.
—
This version removes any informal expressions and maintains a clear and educational tone.
Conditional Statements – Instructions in a program that only run when certain conditions are true. – In our game, the character jumps only if the conditional statement checks that the space bar is pressed.
Scratch – A visual programming language that helps beginners learn to code by snapping together blocks. – We used Scratch to create a fun animation with a dancing cat.
Program – A set of instructions that a computer follows to perform a task. – I wrote a program to calculate the total score of my math quiz.
Fish – A type of character or sprite that can be used in coding projects, often in games or animations. – In my underwater game, the fish swims around collecting coins.
Pufferfish – A specific type of fish sprite that can inflate and deflate, often used in coding projects for fun effects. – When the player gets too close, the pufferfish in my game puffs up to scare them away.
True – A boolean value indicating that a condition or statement is correct or valid. – The program checks if the answer is true before moving to the next question.
False – A boolean value indicating that a condition or statement is incorrect or invalid. – If the answer is false, the program will ask the question again.
Blocks – Visual pieces in Scratch that represent code instructions and can be snapped together to create a program. – I used different blocks to make the character move and speak in my project.
Costume – A different appearance or outfit for a sprite in Scratch, used to change how it looks. – I changed the sprite’s costume to make it look like a superhero.
Loop – A sequence of instructions that repeats until a certain condition is met. – I used a loop to make the character keep walking until it reaches the end of the path.
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |