Events
Send one-shot C# notifications to the UI with Event<T>.
Send an event when something happens in the game, such as taking damage or unlocking an achievement. The UI can respond with a flash, sound, or toast.
Define an event
public sealed class DamageEvent
{
public int Amount { get; set; }
public string Source { get; set; } = "";
}
public Event<DamageEvent> TookDamage { get; } = new();
Fire an event
TookDamage.Fire(new DamageEvent
{
Amount = 12,
Source = "Fire",
});
Listen in the UI
Call onEvent during a Solid component’s setup, beneath BridgeProvider.
The subscription is removed automatically when that component is disposed.
Do not call it at module scope or inside a click callback.
import { createSignal } from 'solid-js';
import { onEvent } from '@loomgui/bridge';
export function DamageNotice() {
const [message, setMessage] = createSignal('');
onEvent('tookDamage', (payload) => {
setMessage(`Took ${payload.amount} damage`);
});
return <output>{message()}</output>;
}
Events vs state
An event is not replayed after the UI reloads. If the UI needs to recover a value, such as the player’s remaining health, expose it as state as well. See The bridge model for when to use state, actions, and events.