Variety is the spice of life!
Variables are a great way to give your program flexibility. For instance, let's say you are creating an RPG game where the action takes place outside. You could set the sky to blue, but what if you wanted it to change depending on the time of day. Then you would setup a variable to represent the sky and it could have different values likes blue for day, black for night, even orange for sunset or sunrise. This example also shows how logic is often used to determine what value a variable should have. If it is nighttime, then the sky is black, else it is blue. For this make, you will control the very sky itself!
Check out the definition of a variable from Scratch. Notice that variables can be set to string (text) or numbers, but unlike lists, a variable can have only one value at a time.
If you've already done the Binary Switch activity, then you have seen an example of a Boolean variable - a variable that only takes on a value of true (1) or false (0).
Create an account on Scratch and then go to Variables, Logic & Makey Makey.
Select See inside code and then Remix.
Find the Variables code (orange) and see the variable sky.
Select the Stage. Notice the code is checking forever to see if the variable sky is set to blue, black or orange.
Scroll down farther and see what keys will cause the sky to change.
Create a color coded game controller with your Makey Makey kit, to control the very skies above!
Try adding another sky backdrop (eg. sunrise, stars, rain, etc) and the logic needed to change to that backdrop.
There's another variable in this project called Yspeed. It helps simulate gravity. Go to Sprite1 and try changing it's initial value. What happens?
Try adding a variable to get sound to play into the project. What logic will you need to have to make the sound play?
Check out the Logic Gate. Can you predict the answer?