ReferenceVerse

Guard Clause Validation

guard clause validation

Updated
Watch the Knot — guard-clause-validation in ~90 seconds.

The seaplane at Coconut Cay Airstrip only roars to life for pilots at full health, instantly rejecting anyone who limps up to the boarding button.

That quick rejection is a guard clause, a validation gate that checks your preconditions and bails out early so your main logic never runs on bad state.

We unwrap the agent and character, then check if health is below 100 — if it is, we return immediately, skipping the takeoff message entirely.

Use guard clauses to fail fast and keep your core game logic clean, safe, and free from messy nested ifs.

airstrip_guard := class(creative_device):
    @editable
    BoardButton : button_device = button_device{}
    OnBoard(Agent : ?agent) : void =
        if (Player := Agent?, Char := Player.GetFortCharacter[]):
            if (Char.GetHealth() < 100.0):
                return
            Print("Cleared for takeoff!")
    OnBegin<override>()<suspends>:void =
        BoardButton.InteractedWithEvent.Subscribe(OnBoard)

Build your own lesson with guard-clause-validation

Generate a personalized, compile-checked lesson grounded in this exact reference.

Build a lesson →