createGameSignalfunctionnacatamalon
createGameSignal() => TGameSignal<T>Makes a signal: a way for one part of the game to say "this happened" and for any other part to react, without the two knowing about each other.
A button does not need to know about the screen that lights up, and the screen does not need to know about the button: both know the signal. That is what keeps them apart, so either can be changed, removed or duplicated without touching the other.
Make it once, in a file of its own, and import it wherever it is needed. It belongs to the page, not to a game, so it can be fired from outside the canvas too (a web page button, a tool).
emit(value)tells everyone listening, straight away.useSignal(signal, handler)listens from a scene, and stops by itself when the scene goes.connect(handler)listens from anywhere else, and returns the function that stops.
A signal carries events, not state: nothing is kept after emit. What should still be true later
(a score, a level reached) belongs in the game's state, not here.
Example
let score = 0;
// events.ts
export const coinCollected = createGameSignal<number>();
// coin.ts
coinCollected.emit(10);
// hud.ts, inside a scene
useSignal(coinCollected, (points) => { score += points; });