← Game Coding
Game Coding U1-L5 Your First Game Window

Your Own Methods: Down and Reset

Write a line once, use it everywhere. Here's the trick that keeps your code short and your changes easy.

Teacher Notes

Not started yet.

Lesson Goal

Students will add a MinusButton and a ResetButton, write click methods for them, and then write a method of their own called UpdateLabel that shows the count, calling it from all three click methods.

Key Concepts

A method is a named recipe. Writing the steps once and calling the method by name wherever they're needed means a change only has to be made in one place.

Calling a method means using its name followed by parentheses and a semicolon. Without the parentheses, the line does not run the method.

C# is case-sensitive, so UpdateLabel and Updatelabel are two different names. The minus button can still go below zero in this lesson, and the next lesson fixes that.

Where Students Get Stuck

Calling UpdateLabel without parentheses, so the line never runs the method and the label doesn't change. A red error usually shows.

Spelling the method name differently where it's written and where it's called, such as a lowercase letter that should be capital.

Wondering why the number goes negative. That's expected for now, and the next lesson stops it.

Checking the Work

When this lesson is done, the scene should show Main with CountLabel, PlusButton, MinusButton and ResetButton under it, all spelled and capitalized exactly that way.

Pressing F5 should show 0 at the start, the plus button should go up by one, the minus button should go down by one, and the reset button should return the number to 0. The number may go below zero, which is fine for now.

A parent can open Main.cs and compare it to the code in the last Watch It Worked, where the line that sets the label's text appears only once, inside UpdateLabel.

Suggested Videos

Optional. Watch one first, then press Add to put it in the Visual Panel for a student.

Key Vocabulary

Method
A named recipe of code that you write once and can use as many times as you like.
Call
Using a method by writing its name, followed by parentheses and a semicolon.
Case-sensitive
Treating capital and small letters as different, so UpdateLabel and Updatelabel are two names.
Parentheses
The pair of curved marks after a method's name, which tell the computer to actually run it.
Sentence 1 of 26 Tap any sentence to start reading there
Settings

Settings

Stored on this device only. Your key stays in this browser. It is never sent to NexStudents, never shared, and never leaves your machine except to the voice provider it belongs to.

Where to get a key. Google Cloud TTS powers the built-in voices on this page and has a free monthly allowance. ElevenLabs is worth a look if you want a more natural voice and do not mind setting up an account.

Colors

Read-aloud is not available in this browser. Try Chrome or Safari.

Before You Start

The Words

The words this lesson uses. Tap a card to see what it means, then come back to them whenever a question uses one.

Part One

The Questions

0 of 0

Questions about the story you just read. Pick your answer straight off, or press Find it in the story if you would rather hunt for the sentence first.

Part Two

Vocabulary Check

0 of 0

The word cards are at the top of this page. Look back at them as often as you need, then answer.

When you finish: write the answers out in your own words — not copied word for word from the choices. Saying it your own way is the part that proves you understood it. Then use Print Answer Sheet for a one-page record of what was answered and scored.
Homework Sheet: UnavailableThere is no homework sheet for this lesson yet.