Finish one delivery without counting it twice
Add a destination, guard the completion transition, and make success readable.
Godot 4.7.2 stable · standard edition · GDScript · 25 minutes estimated practiceContinue your working project from the previous lesson. Each download is the completed version of this lesson, for recovery and comparison. Start lesson one with checkpoint 01.
Add a destination and a count
Continue from lesson four, or start with checkpoint 04. After the parcel-state declarations and before the @onready variables, add the following two lines.
GOAL is the destination center. deliveries begins at zero. The goal uses the same 38-pixel interaction radius so the rule stays easy to explain.
const GOAL := Vector2(800, 470)
var deliveries := 0Replace try_interact with a complete transition rule
Replace the existing try_interact function with this complete version. The waiting branch still guards pickup. The new carried branch checks the destination distance before moving to DELIVERED and incrementing the count.
A delivered parcel matches neither branch. Pressing Space again therefore cannot increment deliveries a second time. The status message states success in words as well as changing the parcel’s appearance.
func try_interact() -> void:
if parcel_state == ParcelState.WAITING:
if player.position.distance_to(PARCEL_START) > INTERACT_RADIUS:
status.text = "Move beside parcel [P] before pressing Space."
return
parcel_state = ParcelState.CARRIED
status.text = "Carrying parcel. Find DROP and press Space nearby."
elif parcel_state == ParcelState.CARRIED:
if player.position.distance_to(GOAL) > INTERACT_RADIUS:
status.text = "Still carrying the parcel. Move beside DROP, then press Space."
return
parcel_state = ParcelState.DELIVERED
deliveries += 1
status.text = "Delivered! 1 / 1. Restart arrives in lesson 6."
queue_redraw()Draw and explain the destination
Inside _draw(), add the following lines after the wall loop and before the parcel-drawing block. The outlined square and DROP text identify the destination.
Replace the status.text assignment in _ready() with: status.text = "Find parcel [P], press Space nearby, then carry it to DROP and press Space." Keep _add_walls() in place.
- Run a fresh game and walk to DROP without the parcel. Press Space; it should not complete a delivery.
- Collect the parcel and press Space far from DROP. It should remain carried.
- Carry it beside DROP and press Space. The parcel should disappear and the status should say Delivered! 1 / 1.
- Press Space repeatedly near DROP. The count should stay at one. Stop and run again for another attempt; restart is the next lesson.
draw_rect(Rect2(GOAL - Vector2(34, 34), Vector2(68, 68)), Color("417664"), false, 3.0)
draw_string(font, GOAL + Vector2(-25, 6), "DROP", HORIZONTAL_ALIGNMENT_LEFT, -1, 17, Color("214b48"))Check your work.
- Visiting the destination without a parcel does not complete the goal.
- A carried parcel cannot be delivered from across the room.
- A nearby carried parcel completes one delivery.
- Repeated interaction leaves the count at one and preserves the success message.
If something went wrong.
- The count changes only inside the guarded CARRIED-to-DELIVERED transition.
- Keep the pickup branch and the delivery branch in the same function so their state conditions stay visible together.
- The destination drawing belongs before the parcel drawing so a carried parcel remains easy to see.
Ask about one small step.
I am on the delivery lesson of the Godot 4.7.2 One Small Delivery workshop. Help me review the WAITING → CARRIED → DELIVERED transition. I want to prove that reaching DROP empty, interacting from far away, completing a delivery and repeating Space each produce the intended result. Work from my try_interact code and keep the count tied to an actual transition.