Week 2 packet
Student instructions, tasks, and checks. The answer key is not in this packet. Links stay as text. This page does not embed a clip or run a file.
# Week 02 — Programs are observable instructions
## VGC-L006 — Print a first event
**Objective:** Recognize _ready as a one-time scene-start event.
**Time:** 55 minutes
### Instruction
Godot nodes can have scripts. The first line extends Node says which node behavior this script extends. A variable stores a value, while a function groups steps. In C-HELLO, _ready runs after the node enters the scene tree and its children are ready. Indentation puts the increment and print inside that function. Running the scene again creates a new node and resets its variable. Output is a diagnostic tool; it is not automatically visible to a player in an exported game.
### Worked example
A counter lab can store parcels as an int and route_title as a String. print exposes intermediate values; a function such as double_points(n) returns n*2 without needing any artwork.
Scaffold C-HELLO — An observable first script
Setup: Create a Node scene, name root Lab, attach lab.gd. Save as lab.tscn. Run current scene (editor clapboard/Run Current Scene). Output panel shows print output. All unindented lines belong to the script and indented lines belong to the function.
```gdscript
extends Node
var deliveries: int = 0
func _ready() -> void:
deliveries += 1
print("Deliveries: ", deliveries)
```
### Assignment
1. Attach C-HELLO to Lab and run twice, stopping between runs.
2. Change the printed label and initial value to 4, then predict the new output.
### Acceptance checks
- Baseline output is Deliveries: 1 on each fresh run.
- Starting at 4 prints 5 after one increment.
**Submit:** lab.gd, scene and a predicted/observed output note.
**Question:** Why does the second fresh run not print 2?
**Support:** Return to C-HELLO and change one value per run. Write the expected output before running. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.
**Optional extension:** Create another small numeric example and predict the result without executing it first. Document one changed parameter, your prediction, and the observed effect; optional, not required for completion.
**Optional free reading:** [Godot 4.7.2 stable archive and platform downloads](https://godotengine.org/download/archive/4.7.2-stable/), [Godot step by step: nodes, scenes, GDScript, input, signals](https://docs.godotengine.org/en/stable/getting_started/step_by_step/index.html)
---
## VGC-L007 — Use names and types that explain the game
**Objective:** Choose sensible integer, float, Boolean and string values.
**Time:** 55 minutes
### Instruction
An integer counts whole objects, a float measures quantities such as seconds, a Boolean stores true or false, and a string stores text. In your Lab script, add lives as an int, elapsed_seconds as a float, delivered as a bool, and route_name as a String. Names should describe meaning rather than an arbitrary letter. A string containing “3” is text, not the integer 3. Print each variable from _ready to inspect its value. Assignment replaces a value; equality comparison asks whether two values match.
### Worked example
A counter lab can store parcels as an int and route_title as a String. print exposes intermediate values; a function such as double_points(n) returns n*2 without needing any artwork.
Scaffold C-HELLO — An observable first script
Setup: Create a Node scene, name root Lab, attach lab.gd. Save as lab.tscn. Run current scene (editor clapboard/Run Current Scene). Output panel shows print output. All unindented lines belong to the script and indented lines belong to the function.
```gdscript
extends Node
var deliveries: int = 0
func _ready() -> void:
deliveries += 1
print("Deliveries: ", deliveries)
```
### Assignment
1. Declare and print four appropriately typed courier variables.
2. Add one sentence explaining why elapsed time uses a float rather than a whole-number count.
### Acceptance checks
- All four declarations parse in GDScript.
- Quoted route text is distinct from numeric values.
**Submit:** Edited Lab project and a four-row type table.
**Question:** What is the difference between lives = 3 and lives == 3?
**Support:** Return to C-HELLO and change one value per run. Write the expected output before running. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.
**Optional extension:** Create another small numeric example and predict the result without executing it first. Document one changed parameter, your prediction, and the observed effect; optional, not required for completion.
**Optional free reading:** [Godot 4.7.2 stable archive and platform downloads](https://godotengine.org/download/archive/4.7.2-stable/), [Godot step by step: nodes, scenes, GDScript, input, signals](https://docs.godotengine.org/en/stable/getting_started/step_by_step/index.html)
---
## VGC-L008 — Calculate resources and clamp boundaries
**Objective:** Trace arithmetic and preserve a valid range.
**Time:** 55 minutes
### Instruction
Games need limits: a courier cannot have negative energy or exceed a bag’s capacity. Write an expression before adding input. For capacity five and current cargo three, accepting four parcels should produce five rather than seven. GDScript’s clampi(value, minimum, maximum) confines an integer. Arithmetic happens before the function checks limits. Make a small trace table with starting value, change, raw result and bounded result. Predict lower-bound, ordinary and upper-bound cases so a single successful example does not hide a mistake.
### Worked example
A counter lab can store parcels as an int and route_title as a String. print exposes intermediate values; a function such as double_points(n) returns n*2 without needing any artwork.
Scaffold C-TESTS — A tiny pure-function test harness
Setup: Attach to Node TestLab. If using command line, create a separate SceneTree harness rather than running this Node script with --script. Run current TestLab scene in editor; assert reports a failed condition in Debugger. No external test framework or package is needed.
```gdscript
extends Node
func bounded_score(old_score: int, change: int) -> int:
return clampi(old_score + change, 0, 999)
func _ready() -> void:
assert(bounded_score(10, 2) == 12)
assert(bounded_score(0, -3) == 0)
assert(bounded_score(998, 9) == 999)
print("3 score checks passed")
```
### Assignment
1. Write bounded cargo calculations using clampi for (3,+1), (3,+4) and (0,-2), range 0 to 5.
2. Print predicted and observed results.
### Acceptance checks
- Results are 4, 5 and 0.
- A middle case is not incorrectly forced to a boundary.
**Submit:** Lab project and three-case trace table.
**Question:** Why test the middle value as well as the two limits?
**Support:** Return to C-HELLO and change one value per run. Write the expected output before running. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.
**Optional extension:** Create another small numeric example and predict the result without executing it first. Document one changed parameter, your prediction, and the observed effect; optional, not required for completion.
**Optional free reading:** [Godot 4.7.2 stable archive and platform downloads](https://godotengine.org/download/archive/4.7.2-stable/), [Godot step by step: nodes, scenes, GDScript, input, signals](https://docs.godotengine.org/en/stable/getting_started/step_by_step/index.html)
---
## VGC-L009 — Branch on a legal decision
**Objective:** Use if, elif and else to make exclusive outcomes.
**Time:** 55 minutes
### Instruction
A condition chooses which block runs. For a delivery request, first reject a negative quantity, then reject a quantity greater than the bag’s cargo, otherwise accept it. The order prevents a negative request from adding items by subtraction. In GDScript a colon starts each branch and indentation determines its contents. An if/elif/else chain selects at most one branch. Two unrelated if statements can both run, which may be wrong for mutually exclusive outcomes. Start with printed messages before changing any stored cargo.
### Worked example
A counter lab can store parcels as an int and route_title as a String. print exposes intermediate values; a function such as double_points(n) returns n*2 without needing any artwork.
Scaffold C-HELLO — An observable first script
Setup: Create a Node scene, name root Lab, attach lab.gd. Save as lab.tscn. Run current scene (editor clapboard/Run Current Scene). Output panel shows print output. All unindented lines belong to the script and indented lines belong to the function.
```gdscript
extends Node
var deliveries: int = 0
func _ready() -> void:
deliveries += 1
print("Deliveries: ", deliveries)
```
### Assignment
1. Implement a request checker with negative, too-large and valid outcomes.
2. Trace requests -1, 2 and 8 when cargo is 5.
### Acceptance checks
- Each request prints exactly one outcome.
- Only the valid request can reduce cargo.
**Submit:** Request-checking script, scene and three traces.
**Question:** Why can two separate if statements differ from if/elif?
**Support:** Return to C-HELLO and change one value per run. Write the expected output before running. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.
**Optional extension:** Create another small numeric example and predict the result without executing it first. Document one changed parameter, your prediction, and the observed effect; optional, not required for completion.
**Optional free reading:** [Godot 4.7.2 stable archive and platform downloads](https://godotengine.org/download/archive/4.7.2-stable/), [Godot step by step: nodes, scenes, GDScript, input, signals](https://docs.godotengine.org/en/stable/getting_started/step_by_step/index.html)
---
## VGC-L010 — Repeat a known number of steps
**Objective:** Use loops and functions without creating an infinite frame loop.
**Time:** 55 minutes
### Instruction
A for loop repeats over a finite collection. In GDScript, for stop in range(4) visits 0, 1, 2 and 3. A function can return a calculated value so callers can reuse it. Write delivery_bonus(parcel_count) to return parcel_count times two, then call it for counts zero through four. Do not use an endless while loop to animate a game; Godot already calls frame functions repeatedly. A long loop that never ends prevents input and drawing from progressing.
### Worked example
A counter lab can store parcels as an int and route_title as a String. print exposes intermediate values; a function such as double_points(n) returns n*2 without needing any artwork.
Scaffold C-HELLO — An observable first script
Setup: Create a Node scene, name root Lab, attach lab.gd. Save as lab.tscn. Run current scene (editor clapboard/Run Current Scene). Output panel shows print output. All unindented lines belong to the script and indented lines belong to the function.
```gdscript
extends Node
var deliveries: int = 0
func _ready() -> void:
deliveries += 1
print("Deliveries: ", deliveries)
```
### Assignment
1. Create delivery_bonus and print its result for range(5).
2. Explain the last input visited and the number of outputs.
### Acceptance checks
- Outputs are 0, 2, 4, 6, 8 in order.
- There are five results, not six.
**Submit:** Lab project and loop trace.
**Question:** Does range(5) include the integer 5?
**Support:** Return to C-HELLO and change one value per run. Write the expected output before running. Start with the first assigned task and re-run its acceptance test before adding the remaining feature.
**Optional extension:** Create another small numeric example and predict the result without executing it first. Document one changed parameter, your prediction, and the observed effect; optional, not required for completion.
**Optional free reading:** [Godot 4.7.2 stable archive and platform downloads](https://godotengine.org/download/archive/4.7.2-stable/), [Godot step by step: nodes, scenes, GDScript, input, signals](https://docs.godotengine.org/en/stable/getting_started/step_by_step/index.html)
---
