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

Your First C# Script

Your button is a block that doesn't know what to do. Here's how you give it its first set of instructions.

Teacher Notes

Not started yet.

Lesson Goal

Students will attach a C# script named Main.cs to the Main node, print a message from the starting-up method, build the project, read the message in the Output panel, and then change the label's text from code.

Key Concepts

A script is a set of written instructions attached to a node. Godot calls the starting-up method once when the node enters the scene, so anything inside it runs one time when the game begins.

The class name in the file has to match the file name exactly, so Main.cs holds a class named Main. The word partial has to be there too, and Godot's template already includes both.

After changing any C# the project must be built, using the hammer button in the top right or Alt+B. Without a build, Godot keeps running the old code.

Where Students Get Stuck

Leaving the language on GDScript, which is the default in the Attach Script window. The file then ends in .gd instead of .cs, and none of the C# lines will work.

Forgetting to build after typing. The game runs, nothing changed, and it looks like the code is wrong when it just hasn't been built.

Missing a semicolon at the end of a line, which shows a red underline and an error in the bottom panel. Every line that does something ends in one.

Checking the Work

When this lesson is done, the Clicker project should have a file called Main.cs in the FileSystem, attached to the Main node, which shows a small script icon next to its name.

Pressing F5 should show the message Hello from my first script! in the Output panel at the bottom, and the label should read 0 once it's been changed back.

A parent can open Main.cs and compare it to the code in the last Watch It Worked, where the file has the print line and the label line inside the starting-up method.

Suggested Videos

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

Key Vocabulary

Script
A set of written instructions attached to a node.
Method
A named set of instructions that runs at a certain moment, such as when the game starts.
Print
A line of code that sends a message to the Output panel so you can see your code ran.
Build
Turning your C# into something Godot can run, which you must do after every change.
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.