1. design, 2. build, 3. test, 4. repeat
When you think about lists, what comes to mind? To Do lists, grocery lists, playlists? Lists help to keep us organized. Lists are also very handy for computers to keep track of lots of different types of data. In coding, lists are often referred to as arrays. In this activity, we'll be using lists to keep track of musical notes on a scale and then use our Makey Makey creation to play back those notes.
A list is a variable containing multiple other variables. If you've already done the Variables & Logic Activity, then you have seen this is action.
Check out the piano scales chart. In Scratch, the C note is represented by the number 60. The next note higher is C# (61) and the next note lower is B (59). Pick a scale and write down the list of notes in that scale by their corresponding number in Scratch.
Go to Lists & Makey Makey. Select
See inside code and then Remix.
Find the Variables code (orange). See all the lists that have been created: Cscale, Bscale, Dscale, Escale and scales. Notice the lists that refer to musical notes. Does the list of musical notes for a particular scale match? Notice that the list scales, refers to the other lists.
Select the Stage. Notice that the variable scale is being set to an item from the list scales based on the item number. So if the random number generated was 2, scale would be set to Bscale.
Each sprite represents a note on a scale. For each note, we check what the variable scale is set to and then we grab correct item number from the correct list and play that note.
Create an instrument to play sweet music with your Makey Makey kit.
Try adding another scale.
Try adding another note to the scale.
You can also use lists in Scratch to keep track of what the user is doing. Check out 6 FruitcraftRPG. It keeps track of your inventory in a list.
Can you figure out how Scratch Memory uses lists?