CHALLENGE 3: Coins Worth Different Amounts ==================================================================== TASK ---- Give each Coin a random chance (e.g. 20%) of being a "big coin" worth 50 points instead of 10, decided once when it's instanced in main.gd. Have the coin's own coin_collected signal pass its point value as an argument so _on_coin_collected can add the correct amount. SOLUTION CODE - the updated coin.gd ----------------------------------------- extends Area2D signal coin_collected(points: int) var point_value: int = 10 func _ready() -> void: body_entered.connect(_on_body_entered) func _on_body_entered(body: Node2D) -> void: if body.is_in_group("player"): $CollisionShape2D.set_deferred("disabled", true) $Sprite2D.hide() coin_collected.emit(point_value) $AudioStreamPlayer2D.play() await $AudioStreamPlayer2D.finished queue_free() SOLUTION CODE - the updated parts of main.gd --------------------------------------------------- func _ready() -> void: $Player/Health.died.connect(_on_player_died) for pos in COIN_POSITIONS: var coin = CoinScene.instantiate() $CoinSpawner.add_child(coin) coin.position = pos if randf() < 0.2: coin.point_value = 50 coin.get_node("Sprite2D").modulate = Color(1.0, 0.85, 0.2) # tint it gold coin.coin_collected.connect(_on_coin_collected) coins_remaining += 1 func _on_coin_collected(points: int) -> void: score += points coins_remaining -= 1 $HUD/ScoreLabel.text = "Score: " + str(score) if coins_remaining == 0: $WinParticles.restart() print("You collected every coin - you win!") WHY THIS WORKS AS AN ANSWER ---------------------------- coin.gd's own point_value is a plain public variable, defaulting to 10 - since it's set directly on the Coin instance right after instantiate() and before add_child() (or immediately after, as shown), each Coin can carry its own independent value without coin.gd needing to know anything about randomness or probability itself; it just emits whatever point_value happens to already be. Deciding "is this a big coin?" in main.gd, right where each coin is spawned, keeps that randomness in exactly one place rather than duplicated inside coin.gd - matching the chapter's own principle that main.gd is the one script that's allowed to know detailed things about how the game as a whole is configured, while Coin itself stays a simple, reusable, self-contained piece. Changing the signal to coin_collected(points: int) means _on_coin_collected now receives the exact point value of whichever coin was just collected, rather than a hardcoded 10 - so score += 10 becomes score += points, correctly adding 50 for a big coin and 10 for a regular one, with no separate lookup or coin-type check needed in main.gd at all; the coin already tells you exactly what it's worth.