Skip to content

Events: When Something Happens, Do Something

Beginning of the lesson

Events: When Something Happens, Do Something

The idea that makes games, apps, and buttons come alive

Big Idea: An event is something that happens — like a button being clicked or a key being pressed. Programs are built to wait for events and then do something when they happen. We call this simple rule: "When this happens, do that."
By the end you will be able to:
  • say what an "event" is in simple words,
  • explain the rule "when something happens, do something,"
  • name common events like clicks, key presses, and timers,
  • match an event to the action it causes.

1. What is an event?

An event is simply something that happens. In the world of programs, events happen all the time:

  • You click a button.
  • You press a key on the keyboard.
  • A timer reaches a certain time.
  • Two things touch in a game (your player touches a coin).
  • The game starts when you press "play".

A program does not do everything all at once. Instead, it waits and watches for events. When one happens, it runs the instructions you connected to that event. Nothing happens until the event happens!

2. The two parts: the trigger and the response

Every event rule has two parts:

  1. The trigger — the thing that happens (the event). Example: a button is clicked.
  2. The response — what the program does about it (the action). Example: the character jumps.

We join them with the word "when":

When the button is clicked, do make the character jump.

The set of instructions that runs when the event happens has a special name: an event handler. You can think of it as the program's way of "handling" — taking care of — the event.

Continue this lesson on YourAIZone

The full lesson has the complete explanation, worked examples, common mistakes, tests with instant checking and an AI tutor. Start right away as a guest, or create an account to keep your progress.

In the full lesson

  • The complete explanation
  • Worked examples
  • Common mistakes and how to avoid them
  • Test questions: 15
  • AI tutor that answers questions about the topic
  • Progress tracking for students, parents and teachers