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

A Timer That Counts by Itself

Some games keep running while you sit back and watch. Here's how you build a clock that does the clicking for you.

Teacher Notes

Not started yet.

Lesson Goal

Students will add a Timer node named AutoTimer, set its Wait Time to 1 and turn Autostart on, connect its Timeout signal to a method that adds one to the count, and add an Auto button that starts or stops the timer.

Key Concepts

A Timer is a node that rings a signal called Timeout after its Wait Time, and then rings it again and again for as long as it's running.

Connecting Timeout works the same way as connecting a button's Pressed signal, with plus-equals and a method name.

A button that toggles a timer uses if and else, one door for when it's stopped and the other for when it's running.

Where Students Get Stuck

Adding the Timer but leaving Autostart off and never starting it from code, so nothing ever happens.

Leaving Wait Time at 0 or a tiny number, which makes the count climb too fast to follow. Setting it to 1 means one tick a second.

Misspelling the node name in the code, so the timer can't be found. It must be AutoTimer, with a capital A and a capital T.

Checking the Work

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

Pressing F5 should make the number climb by one every second without any clicks, and the Auto button should stop it and start it again. The number should turn red when it passes 100.

A parent can open Main.cs and compare it to the code in the Watch It Worked, where a timer variable, a timer method and an Auto method have been added to the previous lesson's file.

Suggested Videos

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

Key Vocabulary

Timer
A node that rings a signal over and over after a set number of seconds.
Timeout
The signal a timer rings each time its wait time runs out.
Wait Time
The setting that decides how many seconds a timer waits between rings.
Autostart
The setting that makes a timer begin counting as soon as the game opens.
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.