Skip to content

Steamworks API

Full Steam integration for your game.

PRO FEATURE

Steamworks integration requires GemShell Pro.

Access via the global steam object in your game code.

Setup

  1. Enable Steamworks in GemShell settings
  2. Enter your Steam App ID
  3. Build your game

Initialization

Steam initializes automatically. Check availability and load stats:

javascript
// Check if Steam is available
if (typeof steam !== 'undefined' && await steam.isAvailable()) {
  // Steam features available
  const name = await steam.getPersonaName();
  console.log(`Hello, ${name}!`);
  
  // Load stats/achievements from Steam server
  const statsReady = await steam.requestStatsAndWait(3000);
  if (statsReady) {
    console.log('Stats loaded!');
  }
}

IMPORTANT

Before reading or writing stats/achievements, call requestStatsAndWait() once at game start. This loads the player's stats from Steam's servers.

Available APIs

APIDescription
User InfoPlayer data, Steam ID, Friends, Avatars
AchievementsUnlock/query achievements, Stats
Cloud SavesSteam Cloud storage
LeaderboardsGlobal leaderboards
Lobbies & P2PMultiplayer lobbies, P2P networking
Rich Presence"Playing..." status
OverlaySteam Overlay
InputController/Gamepad support
Utils & DLCPlatform info, DLC, Workshop

Quick Examples

Get Player Info

javascript
const steamId = await steam.getSteamID();
const name = await steam.getPersonaName();
const level = await steam.getPlayerSteamLevel();

Unlock Achievement

javascript
await steam.unlockAchievement('FIRST_BOSS');
await steam.storeStats();

Save to Cloud

javascript
const saveData = JSON.stringify(gameState);
await steam.fileWrite('save.json', saveData);

Load from Cloud

javascript
if (await steam.fileExists('save.json')) {
  const data = await steam.fileRead('save.json');
  gameState = JSON.parse(data);
}

Set Rich Presence

javascript
await steam.setRichPresence('status', 'Fighting the Dragon');
await steam.setRichPresence('level', '42');

Submit Leaderboard Score

javascript
const board = await steam.findLeaderboard('HighScores');
if (board) {
  await steam.uploadLeaderboardScore(board, score);
}

Callbacks

Call runCallbacks() regularly to process Steam events:

javascript
// In your game loop
function update() {
  if (typeof steam !== 'undefined') {
    steam.runCallbacks();
  }
  // ... rest of game update
}

Testing

For development, Steam uses App ID 480 (Spacewar) by default.

To test with your own App ID:

  1. Set your App ID in GemShell
  2. Have the game in your Steam library
  3. Run Steam in the background

Feature Detection

javascript
async function initSteam() {
  if (typeof steam === 'undefined') {
    console.log('Steam not available');
    return false;
  }
  
  if (!await steam.isAvailable()) {
    console.log('Steam not running');
    return false;
  }
  
  // Load stats from Steam server (required before reading/writing stats)
  const statsReady = await steam.requestStatsAndWait(3000);
  if (!statsReady) {
    console.warn('Could not load stats');
  }
  
  console.log('Steam initialized');
  return true;
}