Ping
EVENT — *do this WHEN that happens.* An event handler waits, doing nothing, until a specific trigger fires — a button press, a timer, a sensor crossing a line — and only then runs its code. Not a loop that keeps checking; a waiting bell that rings the instant it's struck.
Press play to listen along. The line being read lights up as you go.
Show full transcript
Loading transcript…
On the corner of Loop's workbench hung a small brass bell, and it was doing absolutely nothing.
It had been doing nothing all morning. Sunlight crossed the bench, a moth bumped the window, Loop shuffled papers — and the bell just hung there on its little hook, silent, patient, not so much as a shiver. Beside it a card was pinned to the wood. The card said, in Loop's tidy handwriting: *WHEN struck → run this.*
A new kid drifted over, program half-finished, and frowned at it. "That bell's broken," she said. "It's not doing anything."
"It's the busiest thing in the room," Loop said, not looking up.
The kid squinted. The bell was extremely quiet for something busy.
"Watch." Loop reached over and flicked the bell with one finger. Ping! — a single bright note — and the instant it rang, Bit, the little robot at the end of the bench, snapped its arm up and beeped. The kid jumped. The bell went still again, silent, back to doing nothing.
"See that?" Loop said. "It waited. It didn't check the room a hundred times a second asking is it time yet, is it time yet. It just hung there, resting, costing nothing — until the exact moment it got struck. Then, and only then, it ran." He tapped the card. "When this happens, do that. That's Ping. That's an event."
The kid reached out and flicked it herself. Ping — Bit beeped again, instantly. She flicked it twice more, delighted, and Bit answered every single time, right on the note.
The kid wanted to know why it only ran when struck — why it didn't just run on its own like everything else she'd built.
So Loop told her about Trek, the loop that lived one shelf over. Trek was a little walking gear that went around and around and around, doing its work over and over, never resting, checking and rechecking. "Trek is wonderful," Loop said, "but Trek never sits still. If you asked Trek to watch for a button, Trek would ask is it pressed? is it pressed? is it pressed? forever, until it wore itself out. Thousands of questions a second, and almost every answer is no."
He set Ping and Trek side by side. Trek whirred. Ping hung silent.
"Ping does it the lazy-clever way," Loop said. "Ping doesn't ask. Ping waits to be told. You hook it to a trigger, you write down what to run, and then Ping does the hardest, cheapest thing there is — it does nothing, perfectly, until the one moment that matters." He smiled. "Nothing is a lot of work when you have to do it exactly right."
The kid looked at the silent bell with new respect. It hadn't been broken at all. It had been ready.
The kid decided a bell that quiet belonged at CodeRealm, where they studied the parts a program is built from — so she carried Ping down to Loop's classroom and hung it by the door.
Loop met her there. He didn't ask her to prove Ping was clever. He asked one thing. "What is an event?"
The kid didn't answer with words. She hooked Ping to a big red button, pinned a card beside it that read *WHEN button pressed → Bit spins,* and then stepped back and folded her arms and waited. Nothing happened. The bell hung quiet. Loop raised an eyebrow, testing her — "It's not doing anything."
"It's ready," she said, and pressed the button. Ping! Bit spun in a fast, happy circle and stopped. "It didn't run until the trigger. It waited for one specific thing, and when that thing happened, it ran its code. That's all."
Loop watched Bit come to rest. "You belong here," he said.
Ping's corner of the classroom soon filled up with quiet, waiting bells.
A boy came in one afternoon, stuck and grumpy. He'd built a game where a robot was supposed to react, but it just sat there. "I told it to jump," he said, "and it does nothing. I did all the work and it does nothing."
"Show me," the kid said.
He showed her. His program had Bit asking, over and over, did they press it yet? did they press it yet? — so busy asking that it never had a moment to actually jump. "It's exhausting itself," the kid said. "Let's give it a bell instead."
She hooked a Ping to his button and wrote a card: *WHEN button pressed → Bit jumps. Then she added two more bells. WHEN sensor covered → Bit lights up. WHEN 5 seconds pass → Bit spins.* Three bells, all hanging silent, each waiting for its own one thing.
"Now go on," she said. "Press it."
He pressed the button — Bit jumped, the very instant his thumb hit the key. He laughed, surprised, and covered the sensor — Bit lit up. He waited, holding his breath — and after five seconds, all on its own, Bit spun. Three different triggers, three different bells, each ringing exactly on cue.
"Every one answered the second I did it," the boy said, grinning wide. "It feels alive."
"That's the trick," the kid said. "You stop asking a thousand times, and you just wait for the strike. When this, do that."
Later, when the room was empty, the boy came back with one more question. He was quieter now, watching the row of silent bells.
"When they're just hanging there," he said, "not ringing, not doing anything — how do you know they're still working?"
The kid thought about the first bell on Loop's bench, the one she'd called broken.
"You feel it when it fires," she said. "That's the honest answer. There's this bright little jolt — you press the button and the thing answers right then, the exact moment you made it happen, and it feels wonderful. Quick. Awake. Like the program was listening for you the whole time." She looked at the row of quiet bells by the door. "They're not doing nothing. They're doing the patient thing. They're waiting for their one moment — and when it comes, they don't miss it."
The boy nodded slowly, and headed off still grinning at how fast Bit had answered his call. Behind him the bells hung silent, ready, each one listening for the strike that would wake it.
The CodeRealm ensemble
Ping is part of CodeRealm's distributed-narrative cast. Each character embodies a different curricular primitive; together they teach the full subject.
-
Stash
Variable / storage — the labeled box that holds a value until you call for it
-
Fork
Conditional / branching — chooses a path based on what's true right now
-
Trek
Loop / iteration — keeps going around until the work is done
-
Module
Function / encapsulation — does one job well and can be called anywhere
-
Glitch
Debugging / inspection — finds bugs gently, never shaming; 'there's always a reason'
-
Order
Sequence / syntax — reminds you that order matters in code
-
Row
A list: many values lined up in a numbered row, so you can grab item number three instantly or walk through them one by one.
-
Port
Input and output: the doorway that brings information in from the world (a key press, a sensor) and sends results back out.
-
Shuffle
Randomness: a fresh unpredictable value each time — a dice roll, a shuffled deck — so a program can surprise, vary, and stay fair.