Unleashing Your Creativity: A Game Creator Workshop using ChatGPT

Pratik P Sannakki
AI Skunks
Published in
7 min readFeb 27, 2023

Authors - Pratik P S, Shwetha Mishra, Nicolas Brown (AI Skunks)

This is a workshop proposal for the IEEE Conference on Games 2023 https://2023.ieee-cog.org/

What are large language Models?

Large language models are artificial intelligence systems that can generate human-like text by processing large amounts of natural language data. These models are designed to understand and generate language at a level that is approaching human-level comprehension and production.

The basic architecture of large language models involves training a neural network on massive amounts of text data to develop an understanding of language patterns, syntax, and semantics. The model is then fine-tuned for specific tasks such as text generation, translation, sentiment analysis, and question answering.

Examples of large language models include GPT (Generative Pre-trained Transformer) models such as GPT-2 and GPT-3, BERT (Bidirectional Encoder Representations from Transformers), and T5 (Text-to-Text Transfer Transformer). These models have been used in a variety of applications, such as language translation, content creation, chatbots, and more.

How does ChatGPT work?

ChatGPT works by using a large pre-trained language model that has been trained on a massive amount of text data. The model has learned to recognize and understand the patterns, structure, and meaning of language, and can use that knowledge to generate responses to user input.

When a user inputs a message or question, ChatGPT processes the text input and generates a response by predicting the most likely sequence of words that would follow the input based on its training data. The model uses a technique called “transformer architecture” which is a type of deep neural network that can process input sequences of variable lengths.

ChatGPT also employs a technique called “contextual awareness” to generate more relevant and meaningful responses. It analyzes the context of the conversation, including the previous messages exchanged, to better understand the user’s intent and provide a more appropriate response.

As a language model, ChatGPT is capable of generating a wide range of text, including but not limited to answering questions, providing explanations, making recommendations, generating stories, and even holding a casual conversation. However, it is important to note that while ChatGPT can generate responses that are impressively human-like, it is still an AI system and may sometimes produce nonsensical or inappropriate responses.

Why use ChatGPT to create games? and its Scope.

ChatGPT can be used in game development in a variety of ways, particularly in games that involve dialogue, character interactions, and storytelling. Here are some examples of how ChatGPT can be useful in game development:

NPC Dialogue: ChatGPT can be used to generate dialogue for non-playable characters (NPCs) in a game. By training the model on the game’s lore, backstory, and character personalities, it can generate believable dialogue that is tailored to the player’s actions and decisions in the game.

Quest Design: ChatGPT can be used to generate new quests or missions for the player to undertake. By analyzing the player’s progress in the game, the model can create custom objectives and challenges that are unique to the player’s experience.

Storytelling: ChatGPT can be used to generate dynamic and engaging narratives that respond to the player’s choices and actions. By training the model on the game’s world-building and narrative elements, it can create branching storylines that adapt to the player’s decisions.

Player Support: ChatGPT can be used to provide in-game support and guidance to players. By training the model on the game’s rules and mechanics, it can answer common questions, provide tips and tricks, and help players overcome challenges.

Overall, ChatGPT can add a new level of interactivity and immersion to games, allowing for dynamic and personalized gameplay experiences that respond to the player’s choices and actions.

Our Implementation

Steps to developments

  1. Game Script Generator using the OpenAI API

The API requires the parameters below to generate the required python Game script

# Generate a game description using OpenAI's GPT-3
response = requests.post(
"https://api.openai.com/v1/engines/text-davinci-002/completions",
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {openai_api_key}",
},
json={
"prompt": f"genearte python code for {game_type}",
"max_tokens": 100,
"n": 1,
"temperature": 0.5,
},
)
  1. requests.post(): This is a function from the requests library that sends an HTTP POST request to a specified URL. In this case, it sends a request to the OpenAI GPT-3 API to generate a game description.

2. Model Engine — “https://api.openai.com/v1/engines/text-davinci-002": This is the URL of the OpenAI GPT-3 API endpoint that handles text completions using the text-davinci-002 language model.

3. “Authorization” — f”Bearer {openai_api_key}”: This is a header that includes an authorization token for accessing the OpenAI API. The openai_api_key variable should contain a valid API key.

4. prompt — f”generate python code for {game_type}”: This is a JSON payload that specifies the prompt text for the GPT-3 model. In this case, it prompts the model to generate a game description for a specific game type, which is stored in the game_type variable.

5. max_tokens — 100: This is a parameter that specifies the maximum number of tokens (words or subwords) to generate in the response. In this case, it is set to 100 to limit the length of the generated text.

6. n — 1: This is a parameter that specifies the number of responses to generate. In this case, it is set to 1 to generate a single game description.

7. temperature — 0.5: This is a parameter that controls the randomness of the generated response. Higher values result in more diverse and unpredictable responses, while lower values result in more conservative and predictable responses. In this case, it is set to 0.5 to balance randomness and predictability.

The response received from the api call gets auto saved onto a external python file

  1. Game UI generation

The UI is generated using the Tkinter library.

Steps implemented

  1. Window creation with initial label values set.
# initialize Tkinter window
window = tk.Tk()
window.geometry("300x150")
window.title("Interactive Game")

# create widgets
Situation_label=tk.Label(window, text="")
location_label = tk.Label(window, text=situationGame.location)
action_label = tk.Label(window, text=situationGame.actions[0]+" or "+situationGame.actions[1])
input_entry = tk.Entry(window)
submit_button = tk.Button(window, text="Submit", command=update_output)
output_label = tk.Label(window, text="")
quit_button = tk.Button(window, text="Quit", command=quit_game)

# add widgets to window
Situation_label.pack()
location_label.pack()
action_label.pack()
input_entry.pack()
submit_button.pack()
output_label.pack()
quit_button.pack()
  1. Scene and options updating function upon user’s response.
 define functions for buttons
def update_output():
# get user input and update output label
input_text = input_entry.get()
output_label.config(text=f"You entered: {input_text}")
Situation_label.config(text=situationGame.outcomes[input_text]["text"])
action_label.config(text="")
location_label.config(text="")
if "location" in situationGame.outcomes[input_text]:
location_label.config(text=situationGame.outcomes[input_text]["location"])
else:
location_label.config(text="")


if "actions" in situationGame.outcomes[input_text]:
if len(situationGame.outcomes[input_text]["actions"])==2:
action_label.config(text=situationGame.outcomes[input_text]["actions"][0]+" or "+situationGame.outcomes[input_text]["actions"][1])
elif len(situationGame.outcomes[input_text]["actions"])==1:
action_label.config(text=situationGame.outcomes[input_text]["actions"][0])
else:
action_label.config(text="")

Output

Scene 1: Landing page

Scene 2: Shift in outcome based on user input

Scene 3: Change in plots

Agenda

I. Introduction (5 minutes)

  • Welcome and introductions
  • Brief overview of the workshop’s goals and objectives
  • Explanation of what is Chatgpt and how it can be used to create games

II. Overview on Large Language Models (20 minutes)

  • Explanation on what language model is.
  • Architecture behind large Language models
  • Application of large language model in chatgpt

III. Creating a Text based Situational game using Open AI(40 minutes)

  • Game Script Generation using the OpenAI API
  • Game UI generation

IV. Q&A and wrap-up (20 minutes)

  • Open forum for participants to ask questions and share their experiences with chat gpt and their application in game dev
  • Review of key takeaways from the workshop
  • Suggestions for further reading or resources on chat gpt for game development

In conclusion, the game development workshop using ChatGPT provided a practical introduction to using OpenAI’s GPT-3 language model for building situational games. The workshop covered the entire process of game development, including generating responses using the OpenAI API and creating a user interface using the Tkinter library.

Participants in the workshop were able to explore the potential of natural language processing for game development and learn how to generate game descriptions for different game types using the GPT-3 API. The workshop was a valuable learning experience for developers interested in expanding their skillset and exploring the possibilities of using natural language processing in game development.

Repository link — https://github.com/Pratik-Prakash-Sannakki/CustomGameCreator_ChatGPT_IEEECOG.git

References

  1. OpenAI Docs — https://platform.openai.com/docs/introduction
  2. Tkinter library Docs -https://docs.python.org/3/library/tkinter.html

--

--