Note N1 · Achievement Hunter
LIVE ACHIEVEMENT TRACKING
Live Steam achievement progress: steamworks4j and adaptive polling while the game runs
- Sheet
- ACHIEVEMENT HUNTER
- Topic
- Java · steamworks4j · JavaFX
- Source
- service/ProgressWatcherService.java
- Date
- 2026-11-12
- Reading
- 3 min
Short answer: while the game is running, read the stats of only the achievements the user tracks, at regular intervals (SteamUserStats). Never query
unlocked achievements, skip the run while the app is idle, and once an achievement passes 90% of its target, drop the interval from 3 seconds to 1. Because the
interval is not fixed, don't use scheduleAtFixedRate; use a timer that reschedules itself at the end of each run.
01What is tracked
Some achievements have progress: "kill 1,000 enemies". The user wants to see these live in the transparent in-game panel (Shift+Tab). The app keeps the achievements added to the tracking list in a map. Every run asks Steam for current stats and reads each achievement's value.
stats.requestCurrentStats();
for (AchievementData a : trackers.values()) {
if (a.isUnlocked()) continue; // unlocked achievements are not queried
int value = steam.getStatInt(a.getApiName());
Platform.runLater(() -> a.setCurrentValue(value));
if (strategy.shouldBoost(a)) highPriority = true;
}
02What it doesn't query
- Unlocked achievements: their value no longer changes.
- Untracked achievements: a game can have hundreds; the user follows a few.
- While the app is paused: the run passes without a single query.
03Adaptive interval
The moment the user looks at the panel most is when an achievement is about to unlock. If one of the tracked achievements passes 90% of its target, the interval drops to 1 second; otherwise it is 3 seconds.
public boolean shouldBoost(AchievementData data) {
if (data.isUnlocked()) return false;
double progress = data.getTargetValue() > 0 ? data.getCurrentValue() / data.getTargetValue() : 0;
return progress > 0.90 && progress < 1.0;
}
Because the interval can change on every run, a fixed-rate timer is not used. When a run ends, the next one is scheduled with the interval that applies at that
moment; even if a run throws, the finally block keeps the chain going.
scheduler.schedule(() -> {
try { watchProgress(); }
finally { scheduleNextPoll(); }
}, currentInterval, TimeUnit.MILLISECONDS);
04Profiles by game type
The intervals sit behind an interface (PollingStrategy). Three profiles are defined:
- Balanced: 3 s, 1 s once 90% of the target is passed.
- Fast-paced games: 1.5 s, 0.5 s after 80%.
- RPGs and long grinds: 5 s, 2 s after 98%.
The balanced profile is in use for now; the profile can be changed at runtime with setPollingStrategy.
05UI thread
Values are read on the timer's thread, but the JavaFX UI can only be changed on its own thread. Updates are moved there with Platform.runLater.
The achievement model uses DoubleProperty, so UI elements bound to the value refresh on their own when it changes.
06Not depending on the library version
The names of steamworks4j's stat-reading methods can change between versions. At startup the methods of the SteamUserStats class are scanned with
reflection, and the stat readers (getStatI, getStatF) and the method returning an achievement's unlock time are found by name. If the
unlock-time method is missing, the app logs it and falls back to another path; a different library version becomes a missing feature, not a build error.
07When Steam isn't there
Every run first checks whether the Steam connection is ready and the stats object is available; if not, it silently skips and the timer schedules the next run. When the game closes or Steam restarts, the app does not crash; tracking resumes once the connection comes back.
→More notes from this project
—End of notewritten by MUHAMMEDPYZ