# How to Use GPT-4 to Create Interactive Text-Based Adventure Games

DevFeed: [How to Use GPT-4 to Create Interactive Text-Based Adventure Games](<https://devfeed.tech/articles/make-a-fun-infinitely-replayable-game-in-5-minutes-with-gpt-4-35239.md>)

Original publisher: [Read original article](<http://matt.might.net/articles/make-a-text-game-with-generative-ai/>)

Published: 2023-04-01T15:48:44Z

Content type: tutorial

Language: en

Sources: [Matt Might](<https://devfeed.tech/sources/matt-might.md>)

Topics: [Generative AI](<https://devfeed.tech/topics/generative-ai.md>), [Game engine](<https://devfeed.tech/topics/game-engine.md>), [Development](<https://devfeed.tech/topics/development.md>)

Tags: [game](<https://devfeed.tech/tags/game.md>), [generate](<https://devfeed.tech/tags/generate.md>), [gpt](<https://devfeed.tech/tags/gpt.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [interactive](<https://devfeed.tech/tags/interactive.md>), [make](<https://devfeed.tech/tags/make.md>), [save](<https://devfeed.tech/tags/save.md>), [text](<https://devfeed.tech/tags/text.md>)

## AI overview

This tutorial explains how to use GPT-4 as a game engine for interactive text-based adventure games by defining a fictional universe and designing a prompt to simulate gameplay. It also describes adding a save-game feature so players can save and resume the game state.

## Source excerpt

Compared to prior versions, GPT-4 is more capable at writing fiction. Combined with its advances in reasoning, this allows it to maintain a consistent state in a fictional universe as it emulates a text-based adventure game like the classic Zork. In this article, I'll explain how to convert GPT-4 into a game engine for interactive text-based adventure games with just two simple steps: Create a descriptive lore to define the universe and the player Engineer a prompt to simulate a text-based adventure game You can even add a save game feature that allows you to save the state and resume play later. While GPT-3 works with these techniques, it tends to create worlds with less coherent states and the game has shallower narratives compared to GPT-4. The backstory Figuring out how to create these games emerged from my kids' bedtime. Before they go to bed, I like to spend 15-30 minutes doing something educational and entertaining, such as: reading a book or a graphic novel; doing simple crafts like paper airplanes; asking a question on their mind and searching for the result; choosing an object to have 3D printed by morning; or writing a small program or part of a larger program. Not surprisingly, generative AI expands what you can do in 15-30 minutes! For instance, this image took about 30 minutes from start to finish, combining Midjourney to generate a base image, Lensa to do touch-ups and change the background and then DALL-E to tweak parts of it and extend the borders: The opportunities for text-based gaming turn out to the just as rich! My daughter had created a fictional universe with friends at school, complete with its own lore. So, we dropped in the lore and then asked it to act like a role-playing game in that world. We ended up spending an hour exploring this world brought to life, completing the first "quest" it had imagined for us. Click here to read the rest of the article