Skip to content

Latest commit

 

History

History
107 lines (66 loc) · 5.52 KB

lesson_24.md

File metadata and controls

107 lines (66 loc) · 5.52 KB

Lesson 2.4: Variables

Learning objectives

Students will be able to...

  • Apply variables to track values throughout a script or program.

Materials and preparation

Video resources

Pacing guide

Duration Description
5 minutes Welcome, attendance, bell work, announcements
15 minutes Lecture and introduce activity
25 minutes Lab Activity
10 minutes Debrief and wrap-up

Instructor's notes

Debrief

Go over all of the bugs in the Do Now script with students? (There are at least six.)

  1. In order to control Alonzo's movement with the arrow keys, the if statements need to be in a forever loop; otherwise, the script will run once and complete. Alonzo never moves!

Blue dog 2. Likewise, the script checking for the W-A-S-D keys to move the Blue Dog need to be in a loop or they will also only check for a key press one time and complete. The blue dog never moves, either.

Blue dog 3. In Alonzo's script, the conditional checking for the left arrow key is inside of the conditional checking for the right arrow key, so Alonzo can never move to the left. 4. The if on edge, bounce block in Alonzo's script is inside of the conditional checking for the left arrow key, so Alonzo will run off every edge of the screen, except the left. 5. The fifth bug is more subtle. After the bugs preventing the movement of Alonzo and the Blue Dog have been fixed, the blue Dog says "I got you!" when touched by Alonzo. Since the Blue Dog is supposed to be running away from Alonzo, it doesn't make sense for the Blue Dog to say that when caught. 6. The sixth bug is just good coding style. The Blue Dog has an unused say block in the scripting area that should be deleted.

Did the students have any suggestions about ways to improve the game?

Here are some possible improvements they might have thought of:

  • Have a score counter that increments when the reset message is sent. (After Alonzo catches the blue dog.)
  • Since Alonzo starts on the left of the screen and the Blue Dog starts on the right, have Alonzo be controlled by the W-A-S-D keys and the Blue Dog by the arrow keys. That way, the control keys are on the same side of the keyboard as the sprites they are controlling.
  • Have the computer control the Blue Dog using random movements.
  • Have the computer control the Blue Dog by always moving in the opposite direction from Alonzo.
  • Have the players choose which sprite is being chased at the beginning of the game.

Lecture

Review user input, specifically the answer block.

Answer Block

Ask students to speculate about how the answer block works.

  • Students should recognize that the block must be storing a value somehow and remembering it for later. Ask students whether that type of functionality might be useful in other cases.

Introduce variables

Define and explain the concept of a variable: a location in memory to store a value for retrieval and use later.

Consider introducing variables with an interactive physical demonstration by modifying the The Box Variable Activity for your students.

Demonstrate creating, assigning, and accessing a variable.

  • Point out that a variable can only hold one value at a time.
  • When a new value is assigned, the old value is lost and cannot be recovered.
  • Emphasize the importance of descriptive, readable names for variables.
  • Show that variables are independent.

One variable's value can be assigned to another, as in set var1 to var2 Block, but changing the value of var2 later will not update the value of var1.

Set Var1 to var2 Block

Activity

Briefly demonstrate the pick random 1 to 10 block which will be used in the lab.

Direct students to complete Guessing Game individually or in pairs.

Pick Random 1 to 10 block

Lesson debrief

Discuss and demonstrate one or more students' submissions.

Ask students for commentary on usage and naming of variables throughout script.

Accommodation and differentiation

Advanced students can be encouraged to implement statistics (best score, average guesses/game, number of time each secret number chosen, etc.)

Struggling students can be given script that completes part 1.1, and possibly also part 1.2, to get them started

Students who are particularly overwhelmed should focus only on parts 1.2 and 2.2