Click a button three times and the game has to remember the three. Here's where it keeps that number, and how a click gets through to your code.
Not started yet.
Students will store the count in a whole-number variable, connect the plus button's Pressed signal to a method, and make that method add one and show the new number in the label.
A variable is a labeled box. The label is its name, and what's inside can change. The type int means the box holds whole numbers.
A label's Text holds words, so the number has to be turned into words with ToString before it can be shown.
A signal is like a doorbell. The button rings Pressed when it's clicked, and += says to run a given method when that happens. The count++ shortcut also exists, but the lesson keeps the long form on purpose.
Forgetting ToString, which produces an error that says an int can't be turned into a string. Adding it fixes it.
Putting the count box inside the click method, which makes it start over at zero on every click, so the label only ever shows 1. The box has to live outside, at the top of the class.
Typing the method name differently in two places. C# cares about capital letters, so OnPlusPressed and Onpluspressed are different names.
When this lesson is done, Main.cs should have a count variable and a label variable at the top, the label and button connected inside the starting-up method, and a click method that adds one and updates the label.
Pressing F5 and clicking the +1 button should make the number climb by one each time, 1, 2, 3 and so on.
A parent can open Main.cs and compare it to the code in the last Watch It Worked. The Hello print line may have been removed.
Optional. Watch one first, then press Add to put it in the Visual Panel for a student.
Read-aloud is not available in this browser. Try Chrome or Safari.
Before You Start
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
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
The word cards are at the top of this page. Look back at them as often as you need, then answer.