28. Award points once
Scoring is optional, but it is a useful way to make this example feel familiar. The important rule is that a completed task can award points only once, even if the player repeats commands or drops an item and picks it up again.
| Achievement | Guard variable | Points |
|---|---|---|
| First key pickup | ta_found_key | 1 |
| Unlock cabin door | ta_unlocked | 2 |
| First fuse pickup | ta_found_fuse | 1 |
| Fit fuse | ta_fuse_fitted | 3 |
| Send warning | ta_signal_sent | 3 |
| Total | 10 |
func award(flag: String, points: int) -> void:
if bool(Runtime.variables.get(flag, false)):
return
Runtime.variables[flag] = true
Runtime.variables["ta_score"] = int(
Runtime.variables.get("ta_score", 0)) + pointsThis is the same function printed in Appendix A. It sets the guard before adding points. The HUD label uses Score: $$ta_score of 10. The controller converts the starting score to an integer so the opening display reads 0 rather than 0.0.
For a larger game, give each optional discovery its own guard. Do not use a single “puzzle complete” flag for several independent rewards unless that is the behavior you want.
