Events: When Something Happens, Do Something
The idea that makes games, apps, and buttons come alive
- 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:
- The trigger — the thing that happens (the event). Example: a button is clicked.
- The response — what the program does about it (the action). Example: the character jumps.
We join them with the word "when":
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.