Game score does not work #6

Open
opened 2026-03-14 14:34:25 +00:00 by tas · 1 comment
Owner

3 sessions recorded, all with score 0, level 1, 0 lives used, and end_reason: "quit". The game is sending session start and end correctly, but the end payload always has zeroes — the game client isn't populating the score/level/lives data in the session end request.

3 sessions recorded, all with score 0, level 1, 0 lives used, and end_reason: "quit". The game is sending session start and end correctly, but the end payload always has zeroes — the game client isn't populating the score/level/lives data in the session end request.
Author
Owner

DESIGN.md for reference:

Game Analytics & Highscores

Track comprehensive play session analytics and submit them to a backend service
for leaderboards and gameplay insights. Data flows from C → JS (via EM_JS) →
backend API (via fetch). Desktop builds can write to a local file as fallback.

Metrics to track (GameStats struct)

Per-run (reset on new game / restart):

Metric Type Notes
levels_completed int Incremented on each level exit trigger
enemies_killed int Total kills across all levels
kills_by_type[N] int[] Kills broken down by enemy type
deaths int Player death/respawn count
time_elapsed_ms uint32_t Wall-clock play time (accumulate dt)
shots_fired int Total projectiles spawned by player
shots_hit int Player projectiles that connected with enemy
damage_taken int Total HP lost (before death resets)
damage_dealt int Total HP dealt to enemies
dashes_used int Dash activations
jumps int Jump count
distance_traveled float Horizontal pixels traversed
pickups_collected int Health, jetpack, weapon pickups
longest_kill_streak int Max kills without taking damage
current_kill_streak int (internal, not submitted)

Per-level snapshot (ring buffer or array, flushed on level exit):

  • Level name / generator tag
  • Time spent in level
  • Kills in level
  • Deaths in level
  • Health remaining on exit

Data flow

C (GameStats)                JS (shell.html)              Backend API
 │                            │                            │
 ├─ on victory/game-over ────→│                            │
 │  EM_JS: submit_run()       ├── POST /api/runs ────────→│
 │                            │   { stats JSON }           │── store in DB
 │                            │                            │
 ├─ on leaderboard open ─────→│                            │
 │  EM_JS: fetch_leaderboard()├── GET /api/leaderboard ──→│
 │                            │←─ JSON [ top N runs ] ─────│
 │←─ KEEPALIVE callback ──────│                            │
 │  write to C memory         │                            │
DESIGN.md for reference: ## Game Analytics & Highscores Track comprehensive play session analytics and submit them to a backend service for leaderboards and gameplay insights. Data flows from C → JS (via EM_JS) → backend API (via fetch). Desktop builds can write to a local file as fallback. ### Metrics to track (GameStats struct) **Per-run (reset on new game / restart):** | Metric | Type | Notes | |-------------------------|----------|---------------------------------------------| | `levels_completed` | int | Incremented on each level exit trigger | | `enemies_killed` | int | Total kills across all levels | | `kills_by_type[N]` | int[] | Kills broken down by enemy type | | `deaths` | int | Player death/respawn count | | `time_elapsed_ms` | uint32_t | Wall-clock play time (accumulate dt) | | `shots_fired` | int | Total projectiles spawned by player | | `shots_hit` | int | Player projectiles that connected with enemy | | `damage_taken` | int | Total HP lost (before death resets) | | `damage_dealt` | int | Total HP dealt to enemies | | `dashes_used` | int | Dash activations | | `jumps` | int | Jump count | | `distance_traveled` | float | Horizontal pixels traversed | | `pickups_collected` | int | Health, jetpack, weapon pickups | | `longest_kill_streak` | int | Max kills without taking damage | | `current_kill_streak` | int | (internal, not submitted) | **Per-level snapshot (ring buffer or array, flushed on level exit):** - Level name / generator tag - Time spent in level - Kills in level - Deaths in level - Health remaining on exit ### Data flow ``` C (GameStats) JS (shell.html) Backend API │ │ │ ├─ on victory/game-over ────→│ │ │ EM_JS: submit_run() ├── POST /api/runs ────────→│ │ │ { stats JSON } │── store in DB │ │ │ ├─ on leaderboard open ─────→│ │ │ EM_JS: fetch_leaderboard()├── GET /api/leaderboard ──→│ │ │←─ JSON [ top N runs ] ─────│ │←─ KEEPALIVE callback ──────│ │ │ write to C memory │ │ ```
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: tas/major_tom#6