📚 What are Variables in Scratch?
Imagine you have a special box. You can put a number inside this box. This box is called a variable in Scratch. A variable is like a container that holds information – usually numbers, but sometimes words too!
🛠️ Creating a Variable
Here's how you make your own special box in Scratch:
- ➕ Click on the "Variables" block category.
- ✨ Click the "Make a Variable" button.
- ✏️ Give your variable a name (like "score" or "apples").
- ✔️ Choose if it's for all sprites or just one. Usually, "For all sprites" is best for beginners.
- ✅ Click "OK". Now you have a variable!
🧮 Using Variables
Now that you have a variable, you can use blocks to change its value and see it on the screen.
- ⚙️ Set: This block lets you put a specific value in your variable. For example, "set score to 0" puts the number 0 in the 'score' variable.
- ➕ Change: This block lets you increase or decrease the value in your variable. For example, "change score by 1" adds 1 to whatever is already in the 'score' variable.
- 👁️ Show/Hide: You can choose to display the value of your variable on the Stage or hide it.
🍎 Example: Counting Apples
Let's say you want to count how many apples your sprite eats:
- 1️⃣ Create a variable called "apples".
- 2️⃣ Set "apples" to 0 at the beginning of your program.
- 3️⃣ Every time the sprite eats an apple, use the "change apples by 1" block.
- 4️⃣ Now, the "apples" variable will show you how many apples the sprite has eaten!
💡 Why are Variables Useful?
Variables are super useful because they let your programs remember things and change what happens based on that information. Think about:
- 🎯 Keeping score in a game.
- ⏱️ Tracking the time in a timer.
- 🔢 Storing how many lives a player has left.
❓ Practice Quiz
See if you understand variables! Answer these questions:
- 1️⃣ What Scratch block is used to create a variable?
- 2️⃣ Which block *adds* to the value of a variable?
- 3️⃣ If you 'set' a variable named 'points' to 10, what number is stored in that variable?