# Lesson 2: The Big Game - Variables

## Overview

Students get their first look at the inside of their own video games. They will start development by substituting in new Images, Strings, and Numbers for existing variables.

## Anchor Standard

### Common Core Math Standards

• 6.EE.4 - Identify when two expressions are equivalent (i.e., when the two expressions name the same number regardless of which value is substituted into them). For example, the expressions y + y + y and 3y are equivalent because they name the same number regardless of which number y stands for.

## Objectives

### Students will be able to:

• Examine the structure of an existing program.
• Substitute new values into existing variables of an existing program and describe the effects.

## Vocabulary

• Mod - Short for modification. Games in the real world are often a mod of another game. Othello (or Reversi) is usually considered a mod of the ancient game of “Go”. A mod of a program is one that has been altered to do something slightly different than its original purpose.
• Stub - A function whose domain and range have been designated, but the process to transform the domain into the range has not yet been defined.
• Troubleshooting - When a program generates an unexpected result, a programmer must examine the code to determine the source of the unexpected results (usually an unanticipated input or incorrect handling of an expected input). Sometimes called debugging.

# Teaching Guide

## Getting Started

Diving into the Big Game

The students will create a mod of an existing game. As they make changes to the game, it is possible that they will add code that will either “break” the program (cause nothing to happen) or cause an unexpected outcome. If either of these conditions exist, they will need to troubleshoot or debug the code to determine how to get it working in the proper way. If things go terribly awry and finding a problem is too frustrating, use the Clear Puzzle button in the upper right corner of the workspace. This button will clear your game back to its initial state, so it should only be used as a last resort.

This exercise is a simplified version of a very common real world programming task. Programmers often create mods of programs about which they know very little. They slowly unravel which pieces require further understanding in order to make the mod work the way they want, while leaving other parts of the program completely unexplored.

Many programs and functions are customizable through their arguments (which can be variables or values). When a function is called, its arguments are passed in as variables into the function. In other cases, variables that someone might want to change (sometimes called constants) are often at the top of a piece of code. Having access to the code allows the programmer to change the way the program behaves by setting these variables to different values.

In this lesson, we are creating the mod by changing the variables inside the code. The student has access to the game code and is changing the initial value of the Title, Subtitle, Player, Danger, and Target. As a reminder, the ultimate goal of this game will be to manipulate the player through pressing keys, to avoid the danger, and to make contact with the target. The current lesson has no motion or interactivity. It only changes the look of the game. The motion and interactivity function stubs, such as `update-target` and `update-danger`, will be completed in later lessons.

The blocks menu displays a few new items (Boolean, Conditionals, and Functions) which will be examined in more detail in future lessons. The students should be encouraged to explore each of the sub-menus. However the only navigation required for this level is editing the five color blocks at the top of the function: Title, subtitle, bg (background), player, target, and danger. The difference between the color and black blocks will also be explained in a future lesson.

## Variables in the Big Game

### Online Puzzles

In this stage you'll define and modify variables to changes how some games function. Head to Course B stage 2 in Code Studio to get started programming.

View on Code Studio

### Student Instructions

Let's get started on your Big Game! Here you'll see a whole bunch of placeholder code that you'll eventually replace with your own, but for now we're only going to worry about defining variables. Click "Run" to see what the game looks like with the default values.

View on Code Studio

### Student Instructions

The first step to making this game your own is to give it a good Title. Click edit on the `title` and `subtitle` variables and change them to something new.

View on Code Studio

### Student Instructions

Now let's set the background for your new game. Edit the `bg` variable and select a new background Image from the dropdown.

View on Code Studio

### Student Instructions

Awesome! Now you can update the variables for your Player, Target, and Danger. Feel free to play with all of the variables at this point to make your game look like you'd like it to. Click "Finish" when you're done.

## Standards Alignment

#### Common Core Math Standards

CED - Creating Equations
• A.CED.1 - Create equations and inequalities in one variable and use them to solve problems. Include equations arising from linear and quadratic functions, and simple rational and exponential functions.
• A.CED.2 - Create equations in two or more variables to represent relationships between quantities; graph equations on coordinate axes with labels and scales.
EE - Expressions And Equations
• 6.EE.4 - Identify when two expressions are equivalent (i.e., when the two expressions name the same number regardless of which value is substituted into them). For example, the expressions y + y + y and 3y are equivalent because they name the same number regardles
IF - Interpreting Functions
• F.IF.1 - Understand that a function from one set (called the domain) to another set (called the range) assigns to each element of the domain exactly one element of the range. If f is a function and x is an element of its domain, then f(x) denotes the output of f c
• F.IF.2 - Use function notation, evaluate functions for inputs in their domains, and interpret statements that use function notation in terms of a context.
• F.IF.3 - Recognize that sequences are functions, sometimes defined recursively, whose domain is a subset of the integers. For example, the Fibonacci sequence is defined recursively by f(0) = f(1) = 1, f(n+1) = f(n) + f(n-1) for n ≥ 1.
LE - Linear, Quadratic, And Exponential Models★
• F.LE.1 - Distinguish between situations that can be modeled with linear functions and with exponential functions.
MP - Math Practices
• MP.1 - Make sense of problems and persevere in solving them
• MP.2 - Reason abstractly and quantitatively
• MP.3 - Construct viable arguments and critique the reasoning of others
• MP.4 - Model with mathematics
• MP.5 - Use appropriate tools strategically
• MP.6 - Attend to precision
• MP.7 - Look for and make use of structure
• MP.8 - Look for and express regularity in repeated reasoning
OA - Operations And Algebraic Thinking
• 5.OA.1 - Use parentheses, brackets, or braces in numerical expressions, and evaluate expressions with these symbols.
• 5.OA.2 - Write simple expressions that record calculations with numbers, and interpret numerical expressions without evaluating them. For example, express the calculation “add 8 and 7, then multiply by 2” as 2 × (8 + 7). Recognize that 3 × (18932 + 921) is three t
Q - Quantities
• N.Q.1 - Use units as a way to understand problems and to guide the solution of multi-step problems; choose and interpret units consistently in formulas; choose and interpret the scale and the origin in graphs and data displays.
• N.Q.2 - Define appropriate quantities for the purpose of descriptive modeling.
SSE - Seeing Structure In Expressions
• A.SSE.1 - Interpret expressions that represent a quantity in terms of its context.
• A.SSE.2 - Use the structure of an expression to identify ways to rewrite it. For example, see x4 – y4 as (x2)2 – (y2)2, thus recognizing it as a difference of squares that can be factored as (x2 – y2)(x2 + y2).