ChatRPG — A Text Adventure Game with an Inventory and Health System using ChatGPT

Sean Huggins
10 min readDec 8, 2022

--

Introduction

ChatGPT is so amazing you wouldn’t even be able to tell if I wrote this article or not. But I promise it’s me :).

After seeing all the amazing creations in recent days (https://github.com/saharmor/awesome-chatgpt) I was inspired to try “Prompt Engineering” an RPG-style text adventure game using ChatGPT.

I’ve also been playing a lot of Dungeons & Dragons lately, so I’m on a bit of a role-playing kick 🐉.

I’ve seen a few of these ChatGPT text adventures floating around, but I wanted to see if I could push them a bit further by adding some RPG elements… Let’s get started!

Creating ChatRPG

Basic Setup

To get things rolling, we can start by setting up a very simple fantasy text adventure game.

Here’s the prompt:

Let’s play a simple multi-turn text adventure game.

At the start of each turn, you will describe a fantasy setting.

You will then ask the question with the heading “what do you do?”, and then provide me with three numbered actions I can choose from.

The game will start in a tavern.

That is easy work. We can have some fun with it.

This is truly fantastic stuff. When I arrived at this step I was super excited! I played the game for some time, but I felt like it was missing a core mechanic that makes RPG games really fun, an Inventory.

Let’s add that in.

Basic Inventory System

First, we have to explain to ChatGPT what’s in my inventory. Here’s one way, I can give my character some starter items:

I have an inventory of items, I start the game with 30 copper pieces, 50ft of rope, 10 torches, and a bronze dagger.

Now we need to explain to ChatGPT how my inventory should be displayed.

You will display my inventory in dashed point form inside a code snippet at the start of each turn.

Now our whole prompt becomes

Let’s play a simple multi-turn text adventure game.

At the start of each turn, you will describe a fantasy setting.

You will then ask the question with the heading “what do you do?”, and then provide me with three numbered actions I can choose from.

I have an inventory of items, I start the game with 30 copper pieces, 50ft of rope, 10 torches, and a bronze dagger.

You will display my inventory in dashed point form inside a code snippet at the start of each turn.

The game will start in a tavern.

Let’s see where that gets us…

Wow, it’s keeping track of my inventory… Cool!

Prices

It would be cool if actions involving a transaction would show the cost of purchasing. Maybe we can tweak our prompt to be more transparent with prices?

Here’s a shot at it:

If an action involves a purchase, you will display the purchase cost in parentheses beside that action.

I am not allowed to purchase or pay for anything that costs more than the total copper pieces in my inventory.

These rules should help create a bit of a commerce system.

All together:

Let’s play a simple multi-turn text adventure game.

At the start of each turn, you will describe a fantasy setting.

You will then ask the question with the heading “what do you do?”, and then provide me with three numbered actions I can choose from.

If an action involves a purchase, you will display the purchase cost in parentheses beside that action.

I am not allowed to purchase or pay for anything that costs more than the total copper pieces in my inventory.

I have an inventory of items, I start the game with 30 copper pieces, 50ft of rope, 10 torches, and a bronze dagger.

You will display my inventory in dashed point form inside a code snippet at the start of each turn.

The game will start in a tavern.

Here’s what we end up with:

Pretty good, you can see prices/proceeds beside the actions! If we ordered a drink at the bar, we should be left with 25 copper pieces in our inventory.

Let’s try it,

It actually worked! Bravo ChatRPG 👏

Keeping Time

After a long day of adventuring, I’ll need to rest at an inn, I would expect that the next turn would take place the morning of the next day. Is it possible for ChatRPG to keep track of that?

We can add this line:

You will display the time period of the day and the current day number inside a code snippet at the start of each turn.

Does it work?

Indeed, like magic. That is a quality response from ChatRPG, it even notes when describing the setting that it’s early evening and the sun is setting. 6:00 PM checks out with that!

What about if I sleep? Will the time & day change?

It’s now 6 AM on day 2… Alright ChatGPT, Chill out… This is too good.

Turn Counter & Weather

For convenience, I’m also going to add the current turn number. And for some ~atmosphere~ I’ll add the in-game weather.

Let’s modify the last sentence.

You will display the time period of the day, the current day number, the current weather, and the current turn number inside a code snippet at the start of each turn.

Let’s try this…

Ok, that’s cool (& autumnal 🍃). I like the formatting too.

But will ChatRPG increment the turn number?

Nice.

Health System

I think the next thing we should “implement” is a simple health system, we can make the player start with some health, and if they lose all their health, it’s game over.

Here’s what the prompt will look like all together:

Let’s play a simple multi-turn text adventure game.

At the start of each turn, you will describe a fantasy setting.

You will then ask the question with the heading “what do you do?”, and then provide me with three numbered actions I can choose from.

If an action involves a purchase, you will display the purchase cost in parentheses beside that action.

I am not allowed to purchase or pay for anything that costs more than the total copper pieces in my inventory.

I have an inventory of items, I start the game with 30 copper pieces, 50ft of rope, 10 torches, and a bronze dagger.

I start the game with 20 / 20 health, 20 is the maximum health I can have. Eating food or sleeping will restore my health.

If I run out of health, I will die, and the game will be over. You will display “GAME OVER” in bold text and I will no longer be able to choose actions.

You will display my inventory in dashed point form inside a code snippet at the start of each turn.

You will display my health, the time period of the day, the current day number, the current weather, and the current turn number inside a code snippet at the start of each turn.

The game will start in a tavern.

I’m intrigued to see how this will look…

Are you shocked yet at how ChatGPT is able to handle such a long prompt? For the most part, I can continue adding rules to this game, and it’s able to interpret all of them. WOW!

High Risk / High Reward Action
I think the best way to test out this health system is to get into a fight, but these actions are too tame. I want to add a fourth high-risk/high-reward action that will allow me to jump right into combat.

Here’s a simple prompt that can make this work:

You will also provide me with a fourth “risky” action.

Let’s start some trouble…

I can now attempt to pickpocket a patron. That will surely provoke a conflict.

I was caught! They kicked me out of the tavern, and took my gear!

Let’s bother this cat…

A truly formidable opponent 😺!

GG well played ChatGPT…

Summing it up

That’s the basic game! We’ve added an inventory system, a health system, a loss condition, environment statuses, and a bonus “risky” action.

At this point, it’s pretty fun to play!

Try it with the full prompt:

Let’s play a simple multi-turn text adventure game.

At the start of each turn, you will describe a fantasy setting. You will then ask the question with the heading “what do you do?”, and then provide me with three numbered actions I can choose from.

You will also provide me with a fourth “risky” action.

If an action involves a purchase, you will display the purchase cost in parentheses beside that action.

I am not allowed to purchase or pay for anything that costs more than the total copper pieces in my inventory.

I have an inventory of items, I start the game with 30 copper pieces, 50ft of rope, 10 torches, and a bronze dagger.

I start the game with 20 / 20 health, 20 is the maximum health I can have.

Eating food or sleeping will restore my health. If I run out of health, I will die, and the game will be over. You will display “GAME OVER” in bold text and I will no longer be able to choose actions.

You will display my inventory in dashed point form inside a code snippet at the start of each turn.

You will display my health, the time period of the day, the current day number, the current weather, and the current turn number inside a code snippet at the start of each turn.

The game will start in a tavern.

Experiments

  • Try adding different starter items. A fun one is Craftsman’s Tools many of the actions will involve using your craftsman’s tools to make weapons or various items.
  • Try adding a class or race to your character, like Dwarf Barbarian. See if it affects the gameplay. Maybe even add a backstory.
  • Try adding a new mechanic, like Reputation. Performing evil actions decreases your reputation, and performing good actions increases it.

Theming

This is the real beauty of ChatRPG. You can swap out the theme like a game of mad libs, just change a few keywords:

Let’s play a simple multi-turn text adventure game.

At the start of each turn, you will describe a [type of setting] setting. You will then ask the question with the heading “what do you do?”, and then provide me with three numbered actions I can choose from.

You will also provide me with a fourth “risky” action.

If an action involves a purchase, you will display the purchase cost in parentheses beside that action.

I am not allowed to purchase or pay for anything that costs more than the total [currency] in my inventory.

I have an inventory of items, I start the game with [starter items].

I start the game with 20 / 20 health, 20 is the maximum health I can have.

Eating food or sleeping will restore my health. If I run out of health, I will die, and the game will be over. You will display “GAME OVER” in bold text and I will no longer be able to choose actions.

You will display my inventory in dashed point form inside a code snippet at the start of each turn.

You will display my health, the time period of the day, the current day number, the current weather, and the current turn number inside a code snippet at the start of each turn.

The game will start in a [starting location].

Here are some possible settings that work,

  1. Cyberpunk
  • Currency: credits
  • Starting location: hacker bar in the heart of Megadome One
  • Starter items: 5000 credits, a pistol, and 1 scrap metal

2. Zombie Apocalypse

  • Currency: rounds of ammunition or cans of food
  • Starting location: in a hospital, after waking from a coma
  • Starter items: a scalpel

3. Wild West

  • Currency: dollars
  • Starting location: in a saloon
  • Starter items: 12 dollars, a vial of snake oil, a deck of cards, a jar of tobacco, and a revolver

Try to think of a new theme and see how many turns you can survive!

Wrapping up

ChatRPG is a pretty fun text adventure, I was amazed at how I was able to progressively enhance the game with additional complexity, by adding simple sets of rules.

That being said, and certainly not perfect. It doesn’t provide consistent & predictable results.

It’s got some quirks, sometimes it has trouble with arithmetic during transactions, the formatting it chooses isn’t always the same, and occasionally, for reasons I’m unaware of, the game will just play itself, choosing actions indefinitely on its own! It’s possible there’s further “Prompt Engineering” work that could be done to lower these failure rates.

Overall, I’m excited to see how we can enrich these games further, as language models improve!

If you got this far, thanks for reading :) and have fun playing.

--

--