P1.1 — What a Program Is, and Running One¶
What you'll learn
- What a program is: an ordered list of instructions a computer follows, top to bottom.
- That code lives in a script, and how to attach one and run it in Godot.
- How to make the computer show you something with
print, and where that output appears. - That a program does its steps in order — and that the order is part of the meaning.
How it applies
- Order is meaning. A program runs its lines top to bottom, so "ask the name, then greet" and "greet, then ask the name" are different programs with different results. Most early bugs are not typos — they are steps in the wrong order.
printis how you see inside. A running program is invisible unless it tells you what it did.printis the window: it turns "I think this ran" into "I can see it ran, and here is the value." Every later chapter leans on it.- You run the saved version. The computer runs the file as last saved, not the unsaved text on your screen. Forgetting to save is the classic "I fixed it but it still does the old thing."
- Running the wrong thing shows nothing. Launching the whole project when you meant to test one small scene is how beginners stare at a blank window wondering why their code "did nothing."
Concepts¶
A program is an ordered list of instructions¶
A program is a list of instructions a computer carries out, one after another, from the top of the list to the bottom. That is the whole idea. A useful comparison is a recipe: "crack the eggs, then whisk them, then pour into the pan." The steps happen in order, and doing them out of order gives a different result.
The instructions are written as text, in a programming language. This book uses GDScript, the
language built into Godot. A file of GDScript is called a script, and it has the extension .gd.
A script, and the frame your code goes in¶
In Godot, a script is usually attached to a node (you will learn what nodes are in a later book — for now, a node is just "the thing the script is attached to"). Every script you write in this book starts with the same two lines of frame:
You will learn exactly what extends Node and func _ready() mean in the next book. For now, treat
them as the frame: extends Node says what the script is attached to, and _ready() is the place
whose code runs once, automatically, when you start the program. Your instructions go on the indented
lines beneath _ready(). The indentation (a tab) is how GDScript knows those lines belong inside
_ready.
Making the computer speak: print¶
The simplest instruction is print, which displays text:
print("Hello.") tells the computer to write Hello. to the Output panel at the bottom of the
Godot editor. The text inside the quotes is what gets shown. This is your first complete program: a
frame, and one instruction inside it.
Example
Because instructions run top to bottom, two prints appear in the order you wrote them:
Output:
Swap the two lines and the output swaps too. The computer is not choosing an order — it is simply doing what is written, from the top. That predictability is the foundation everything else is built on.
Running it¶
To run the program, you press a key and Godot starts it in a separate window. There are two run keys;
for everything in this book you want F6, which runs the single scene you are editing by
itself. (The other key, F5, runs the whole project from its starting scene — not what you want for
small experiments.) When the program runs, _ready fires, your print executes, and the text appears
in the Output panel.
Walkthrough¶
Do this in Godot 4.6. You will not build a game — just run a script.
- Make sure you have a project open (create a new empty one if needed). In the Scene panel (top-left), click Other Node, choose Node, and confirm. You now have one node.
- Right-click that node → Attach Script. Accept the defaults and click Create. The script
editor opens, already showing
extends Nodeand a_ready()function. - Inside
_ready()(on the indented line), typeprint("Hello.")— type it, do not copy. Getting it slightly wrong and fixing it is part of learning. - Save with Ctrl+S (save the scene too if asked). Press F6. A window opens, and the Output
panel shows
Hello. - Add a second
printwith different text below the first. Save, run, and confirm both lines appear in the order you wrote them. Then swap the two lines, save, run, and watch the order change.
Optional sanity check
Change the text in a print, then run without saving first. The old text still appears, because
the computer ran the last saved version. Save, run again, and the new text appears. That is the
"you run the saved version" rule, seen for yourself.
Self-check quiz¶
Q1 — In what order does a program run its instructions?
A. In a random order the computer chooses. B. Top to bottom, one after another, as written. C. Bottom to top. D. All at the same time.
Reveal answer
B. A program carries out its instructions in order, from the top of the list to the bottom. A and D imagine the computer making choices or doing everything at once — it does neither; it follows the written order exactly. C reverses it.
Q2 — What does print(\"Score\") do?
A. Sends the text to a printer.
B. Writes Score to the Output panel so you can see it.
C. Creates a variable called Score.
D. Nothing until the game ends.
Reveal answer
B. print writes the text inside the quotes to the editor's Output panel — your window into
what the program is doing. A takes "print" literally (no paper involved). C describes variables
(next chapter). D invents a delay that does not exist.
Q3 — You change a print, run, and the old text still shows. The most likely reason?
A. The computer is broken.
B. You did not save the file, so it ran the previous saved version.
C. print only works once.
D. You need to restart Godot.
Reveal answer
B. Running uses the last saved version of the file; an unsaved edit is not part of the run.
Save (Ctrl+S), then run. A and D over-react to a simple cause. C invents a limit print does
not have.
Integration question¶
Q4 — open
You write two instructions: print("What is your name?") and print("Nice to meet you!"). In one
version the question comes first; in another, the greeting comes first. Using this chapter's central
idea, explain why these are genuinely different programs even though they contain the exact same
two lines, and what that tells you to check first when a program does the right things in the wrong
sequence.
Reveal expected answer
A program's meaning is its instructions in order: the computer runs them top to bottom, so the
version that prints the question first and the version that prints the greeting first produce
different output sequences — they are different programs despite sharing the same two lines.
Nothing about the lines themselves changed; only their order did, and order is part of what the
program is. The practical lesson: when a program produces the right pieces in the wrong
sequence, suspect the order of the instructions before suspecting the instructions
themselves. Reordering lines is often the entire fix, and it is the first thing to check — which
is also why print is so useful, since it lets you see exactly what happened and in what order.