Getting started

Install the SDK in a browser game, call connect() during startup, and wait for it before using Plot features. The first release will return a small client that only confirms the connection.

Pre-release status: @plot.game/sdk@0.1.0 is not on npm yet. The install and CDN examples below will work after the first package publication.

Install with npm

npm install @plot.game/sdk

Import the default SDK object and connect during game startup:

import PlotSDK from '@plot.game/sdk'

const plot = await PlotSDK.connect()

console.log(plot.connected)

Normal games do not need connection options. PlotSDK.connect() is safe to call more than once, and a failed attempt can be retried.

Your game is loaded inside Plot. Opening the game URL directly in a browser tab is useful for ordinary UI work, but connect() will reject because there is no Plot session around it.

Show a useful connection state

Connect before showing controls that depend on Plot, and handle failure as part of the game's startup screen:

import PlotSDK, { PlotConnectionError } from '@plot.game/sdk'

// These two functions belong to your game.
try {
  const plot = await PlotSDK.connect()
  startGame(plot)
} catch (error) {
  if (error instanceof PlotConnectionError) {
    showConnectionProblem(error.code)
  } else {
    throw error
  }
}

Use the stable error code for logic. The message is intended to help a developer diagnose the problem. See PlotConnectionErrorCode for the complete list of codes.

Use a browser script

A game without a package manager can load the IIFE build from a CDN. Pin the complete package version so a published game never changes underneath you:

<script
  src="https://cdn.jsdelivr.net/npm/@plot.game/sdk@0.1.0/dist/plot-sdk.iife.js"
  integrity="sha384-G9nlrHc6CVAWjsoGR0ER8yF10GhHgv4oDvYm//zz5ZpMEl+TqiOo32dP8UHuTly4"
  crossorigin="anonymous"
></script>
<script>
  void (async () => {
    const plot = await PlotSDK.connect()
  })()
</script>

The CDN URL will become available after the first npm release. Every release includes dist/integrity.json; copy its SHA-384 value when updating the pinned version.

Published games should always pin the complete SDK version, whether the SDK is installed from npm or loaded from a CDN. Continue with local development, or read the full API reference.