Skip to content

Instantly share code, notes, and snippets.

@jletourneau
Created October 24, 2012 15:02
Show Gist options
  • Save jletourneau/3946588 to your computer and use it in GitHub Desktop.
Save jletourneau/3946588 to your computer and use it in GitHub Desktop.
Plugging Hydra into your game

Plugging Hydra into your game

This documentation explains how to build Hydra profile support into an existing game. As our example, we’ll be working with a very simple “game” called Masher, written in Python, which prompts the user for their name, reads lines of input one at a time, and adds up the number of characters the user has entered.

The original version of the game stores the user’s name, rounds played, and count of characters typed in a data structure which is saved to a file on disk using Python’s pickle module. Our goal is to modify this game to store the player’s data in Hydra instead.

Setting up Hydra to start accepting data

We will be making HTTP requests to Hydra’s REST API for reading and writing player data, but before we get started, we need to do some setup (for the purposes of this documentation, it’s assumed we already have a Hydra account). We need three things:

  • A project
  • An environment
  • An API key

Projects correspond to game titles. Environments belong to projects, and serve as containers for different groups of players (e.g. players on different platforms for a multi-platform game; in the case of Masher, one environment will suffice). An API key will grant us access to read from and write to the environment we set up.

TODO: describe UX for creating project/environment/API key in dashboard

Transitioning from local storage to Hydra

We won’t be doing away entirely with the filesystem in our demo game; the change will be that the file we write to disk will store only the player’s Hydra ID, rather than their actual stats. The player’s name and counts of rounds played and characters typed will be saved to Hydra.

Initializing a new user

Reading an existing user profile

Writing values to the profile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment