> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Writing an event to power an event-based stat

> Sample XblEventsWriteInGameEvent code that fires an XBOX Live event so configured stat rules update event-based user stats on the service.

This topic provides example code that shows how to write an event.
On the service, this example code updates event-based stats based on the stat rules that you've defined in Partner Center.

#### Flat C API

```cpp theme={null}
HRESULT hr = XblEventsWriteInGameEvent(
    xboxLiveContext,
    "PuzzleSolved",
    R"({"DifficultyLevelId":100, "GameplayModeId":"Adventure"})",
    R"({"LocationX":1,"LocationY":1})"
);
```

For more information, see
[XblEventsWriteInGameEvent](/reference/live/xsapi-c/events_c/functions/xbleventswriteingameevent).


## Related topics

- [Event-based Stats & Leaderboards example code](/services/xbox-services/player-data/stats-leaderboards/event-based/how-to/live-statslb-eb-howto-nav.md)
- [Leaderboards](/build/steam-porting-guide/features/steam-leaderboards.md)
- [Writing an event to power an event-based achievement](/services/xbox-services/player-data/achievements/event-based/how-to/live-writing-event-based-achievement.md)
- [Events overview](/services/xbox-services/player-data/stats-leaderboards/event-based/events/live-game-events.md)
- [First glance for event-based Stats](/services/xbox-services/player-data/stats-leaderboards/event-based/config/live-stats-first-glance.md)
