> ## Documentation Index
> Fetch the complete documentation index at: https://docs.forgegames.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Build Your Game's Inventory System

> Learn how to set up a basic inventory system using Forge. You'll define items, create spaces to store them, and assign them to users.

### **Step 1: Define Items**

Define the items in your game. Items can be as simple or complex as your game requires.

#### **Optional: Add Classifiers**

Classifiers categorize items for easier filtering and organization:

* **Rarity** (e.g., "Common", "Rare", "Legendary")
* **Type** (e.g., "Weapon", "Armor", "Consumable")

Skip classifiers if your items don’t need categorization.

#### **Optional: Add Attributes**

Attributes define item properties or stats:

* **Attack Power** (e.g., "+10")
* **Health Restoration** (e.g., "Restore 50 HP")

If your game doesn’t require detailed item properties, you can leave attributes out.

***

### **Step 2: Define Spaces**

Spaces are areas where items are stored. Create spaces for player inventories, stashes, or other storage systems.

**Examples:**

* `Inventory`: A general storage space for all collected items.
* `Stash`: A special storage space for rare or extra items.

***

### **Step 3: Create the Forge Client**

Connect your game to Forge using your credentials. The client securely interacts with Forge’s API.

```ts theme={null}
// Initialize the Forge client with your credentials
const client = new Forge({
  username: process.env['FORGE_CLIENT_ID'], // Your client ID
  password: process.env['FORGE_CLIENT_SECRET'], // Your client secret
});
```

***

### **Step 4: Add a User**

Players in your game are represented as users in Forge. When a player logs in or selects a character, create a user.

```ts theme={null}
// Create a new user in Forge
const user = await client.users.create();
```

* **What does this do?**\
  Creates a user profile in Forge, which can be linked to items and spaces.

***

### **Step 5: Create a Space for the User**

Assign the user a storage space for their collected items, such as an inventory or stash.

```ts theme={null}
// Create a user space for the player's stash
const userSpace = await client.users.spaces.create(user.id, {
  spaceId: process.env['FORGE_STASH_SPACE_ID'], // ID of the defined space
  externalId: user.id, // Optional: Link to your game’s user ID
});
```

* **What does this do?**\
  Creates a unique storage space for the user, enabling item collection and organization.

***

### **Step 6: Create an Item Instance**

Add an item instance to the user’s space. For example, if a player defeats a monster and collects a legendary sword, you can add it to their stash.

```ts theme={null}
// Add an item instance to the user's stash
await client.itemInstances.create({
  userSpaceId: userSpace.id, // The user's stash space
  itemId: <<DEFINED_ITEM_ID>>, // The item the user collects
});
```

* **What does this do?**\
  Creates a unique instance of the item (e.g., a specific sword) and places it in the user’s space.
