# Variable Prompt

{% hint style="info" %}
🚀 **Premium Feature**: The Variable Prompt is a premium component that requires an upgraded UFOLab subscription to use in your games.
{% endhint %}

The **Variable Prompt** is an advanced component that allows you to collect custom information from players and store it as variables in your game. Think of it as a way to personalize your game experience by asking players to provide specific information that can be used throughout the game - like their name, preferences, or any other custom data you need.

## Overview

The Variable Prompt creates a simple form where players can enter text that gets stored as a game variable. This variable can then be used anywhere in your game through text templating, making your content dynamic and personalized. It's perfect for creating engaging, customized experiences where players feel like the game is responding to their input.

![Variable Prompt component in the editor showing the userName template](/files/hxhuYcGNHl7AxyRuD6ke)

## How to Add a Variable Prompt

1. Open your game in the UFOLab editor
2. Navigate to the **Components** section in the component picker
3. Select **Variable Prompt** from the advanced components
4. Drag and drop it onto your scene

![Adding Variable Prompt from component picker](/files/XQtR0QFQ7JDPwk8Va1MH)

## Setting Up Your Variable Prompt

### Choose Your Variable Template

The Variable Prompt comes with pre-configured templates to make setup easier. Currently available:

#### User Name Template

* **Variable Name**: `userName`
* **Purpose**: Collects the player's name for personalization
* **Use Case**: Perfect for creating personalized experiences

### Configure Your Settings

Click on your Variable Prompt component to access the configuration options:

![Variable Prompt configuration panel](/files/FOcGrI4fnjL0YLE2UUXZ)

#### General Settings

**Variable Name** (Hidden)

* This is automatically set based on your chosen template
* For the User Name template, this is set to `userName`
* The variable name is how you'll reference this data in your game

**Allow Repeated Submit**

* **Default**: `false` (recommended)
* When `false`: Players can only submit their input once
* When `true`: Players can change their input multiple times
* **Best Practice**: Keep this `false` for user names to maintain consistency

## Using Variables in Your Game

Once a player submits their information through the Variable Prompt, you can use that data anywhere in your game using text templating.

### Text Templating Syntax

Use double curly braces to reference your variables in any text component:

```markdown
{{variableName}}
```

### User Name Examples

Here are practical examples of how to use the `userName` variable:

#### Welcome Messages

```markdown
Welcome to the adventure, {{userName}}!
```

#### Personalized Instructions

```markdown
{{userName}}, you need to find the hidden treasure in the next room.
```

#### Dynamic Dialogue

```markdown
"Hello {{userName}}! I've been waiting for you. The kingdom needs your help!"
```

#### Achievement Messages

```markdown
Congratulations {{userName}}! You've completed the first level!
```

### Setting Up Text with Variables

1. Add a **Text** component to your scene
2. In the text content, type your message using the variable syntax
3. The variable will be automatically replaced with the player's input when the game runs

![Text component showing variable usage](/files/jfecWTmUQpwPd0Mb5sf5)

## Actions Setup

{% hint style="warning" %}
⚠️ **Important**: Actions are required for the Variable Prompt. You must set up what happens when the player submits their information so the user gets some feedback.
{% endhint %}

### Required Actions

When the player submits their information, you need to define what happens next:

1. Click on your Variable Prompt component to select it
2. Look for the **Actions** tab in the properties panel
3. Set up the **"When Submit"** action

![Action configuration panel](/files/ipidJg0BuSxavu6mj9Zq)

### Popular Actions After Submit

* **Go to another scene** - Move the player to the next part of your game
* **Show a welcome message** - Display personalized content using the variable
* **Start a timer** - Begin a countdown or timed challenge
* **Reveal game elements** - Show hidden components or information
* **Play sounds** - Trigger audio feedback or background music

## Future Use Cases

The Variable Prompt is designed to be extensible. While currently focused on user names, future updates will include additional templates for:

* **Player preferences** - Difficulty level, game mode selection
* **Custom data collection** - Survey responses, feedback, choices
* **Personalization settings** - Avatar names, character customization
* **Educational data** - Student information, class details

The component structure is built to easily accommodate these future enhancements while maintaining the same simple setup process.

## Integration with Premium Features

### Ranking Component (Coming Soon)

The `userName` variable collected by the Variable Prompt will be used by the upcoming **Ranking** component, another premium feature that will:

* Display player names in leaderboards
* Show personalized achievement lists
* Create competitive experiences with named participants

This integration makes the Variable Prompt an essential component for creating engaging, competitive game experiences.

## Popular Ways to Use Variable Prompt

### Personalized Learning Experiences

Create educational games where students feel personally engaged:

**Example Flow:**

```
1. Variable Prompt: "What's your name?"
2. Text: "Welcome {{userName}}! Today we'll learn about..."
3. Personalized feedback throughout the lesson
4. Final message: "Great job {{userName}}! You've mastered the topic!"
```

### Interactive Stories

Make players the protagonist of their own adventure:

**Example Flow:**

```
1. Variable Prompt: "What should we call our hero?"
2. Story text: "{{userName}} walked into the mysterious forest..."
3. Character dialogue: "{{userName}}, you must find the ancient artifact!"
```

### Corporate Training

Personalize professional development content:

**Example Flow:**

```
1. Variable Prompt: "Enter your employee ID"
2. Training content: "Hello {{userName}}, let's review your training progress..."
3. Personalized completion certificates
```

## If Something's Not Working

### My Variable Isn't Showing Up in Text

**Check these common issues:**

* Make sure you're using the correct variable name: `{{userName}}` (case-sensitive)
* Verify that the player has actually submitted their information through the Variable Prompt
* Ensure the text component is on the same scene or a later scene (variables persist throughout the game)
* Check that you've set up the submit action properly

### The Variable Shows as Empty

* Make sure the Variable Prompt has been submitted at least once
* Verify that the variable name in your text matches exactly: `{{userName}}`
* Check that the Variable Prompt is enabled and working properly

### Players Can't Submit Their Information

* Ensure you've set up the "When Submit" action
* Check that the Variable Prompt component is enabled
* Verify that "Allow Repeated Submit" is set appropriately for your use case

## Creative Tips

### Create Variable Chains

Use multiple Variable Prompts to collect different types of information:

**Example - Character Creation:**

1. Variable Prompt 1: "What's your hero's name?" → {{userName}}
2. Text: "The hero, {{userName}}, begins their quest..."

### Combine with Other Components

Use variables with other advanced components for rich interactions:

* **Action Scheduler** + Variable: "{{userName}}, the timer starts now!"
* **Dialogue** + Variable: Character says "Hello {{userName}}!"
* **Quiz** + Variable: "{{userName}}, here's your personalized quiz!"

### Smart Defaults

Consider what happens if players don't provide information:

* Use fallback text: "Welcome, {{userName}}!" (shows as "Welcome, !" if empty)
* Or create conditional logic with other components to handle empty variables

***

The Variable Prompt is an amazing way to make your games feel personal and engaging. By collecting player information and using it throughout your game, you create experiences that feel tailored to each individual player, making your content more memorable and impactful.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://academy.theufolab.com/game-editor/components/subcomponents/variable-prompt.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
