<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Documentation - verse-starter-04-representing-command-data-for-in-unreal-editor-for-fortnite</title>
  <style>
    body { 
      font-family: monospace; 
      margin: 0;
      padding: 0;
    }
    pre { 
      background-color: white; 
    }
  </style>
</head>
<body>
  <pre>1.  ![Epic Games](https://edc-cdn.net/assets/images/logo-epic.svg)[Developer](/)
2.  [Documentation](/documentation/ "Documentation")
3.  Fortnite
    *   [Unreal Engine](/documentation/en-us/unreal-engine)
    *   [Fortnite](/documentation/en-us/fortnite)
    *   [MetaHuman](/documentation/en-us/metahuman)
    *   [Twinmotion](/documentation/en-us/twinmotion)
    *   [RealityScan Mobile](/documentation/en-us/realityscan-mobile)
    *   [Fab](/documentation/en-us/fab)
4.  [Fortnite Documentation](/documentation/en-us/fortnite/fortnite-documentation "Fortnite Documentation")
5.  [Get Started Creating in Fortnite](/documentation/en-us/fortnite/get-started-creating-in-fortnite "Get Started Creating in Fortnite")
6.  [Verse Language Get Started](/documentation/en-us/fortnite/verse-language-get-started-in-unreal-editor-for-fortnite "Verse Language Get Started")
7.  [Verse Starter Template](/documentation/en-us/fortnite/verse-starter-template-in-unreal-editor-for-fortnite "Verse Starter Template")
8.  4\. Representing Command Data

4\. Representing Command Data
=============================

Learn how to represent and use the character commands in Verse code.

![4. Representing Command Data](https://uefn-docs.yuzulabs.dev/community/api/documentation/image/9855a06e-10af-4064-acea-c66c0d55c1db?resizing_type=fill&width=1920&height=335)

On this page

A common pattern in programming is creating a data representation of a concept, like character commands, that you can pass around and treat as data within your code. In this minigame, commands need to be treated as data to generate from the UI interaction and pass to the character to perform.

In this project, a command is represented as an [abstract](https://uefn-docs.yuzulabs.dev/documentation/en-us/fortnite/subclass-in-verse) class, and each specific command is a subclass of this `command` class, such as `forward_command` and `turnright_command`. Using an abstract class for the command means that the only valid commands are the subclasses that are not abstract. If you try to create an instance of the `command` class directly, you'll get an error when you try to compile your code.

Because the character commands are subclasses of the `command` class, you can use them anywhere the `command` class is expected, such as the character's `ExecuteCommand()` function in the previous step. The first parameter in `ExecuteCommand()` expects the command type, which means you can use an instance of a `command` subclass as the argument without issue.

[![Using subclasses of the command class as data for the character to perform.](https://uefn-docs.yuzulabs.dev/community/api/documentation/image/0ffd48e6-9697-439a-9975-ca90d8c73836?resizing_type=fit)](https://uefn-docs.yuzulabs.dev/community/api/documentation/image/0ffd48e6-9697-439a-9975-ca90d8c73836?resizing_type=fit)

Each subclass provides its own implementation of `DebugString()` so when you print a command value it has the correct text associated with it, but you can add more differences to the classes if you need to.

These classes also have the [unique](https://uefn-docs.yuzulabs.dev/documentation/en-us/fortnite/class-in-verse) specifier so we can compare instances of the classes. This specifier makes them comparable.

The classes also have the [computes](https://uefn-docs.yuzulabs.dev/documentation/en-us/fortnite/specifiers-and-attributes-in-verse) specifier so you can create instances of them at module-scope (in the `Commands` module directly). This means we can create a single unique instance to represent each command, for example, `Commands.Forward` for the forward command.

This example uses instances of command subclasses instead of the [enum](https://uefn-docs.yuzulabs.dev/documentation/en-us/fortnite/enum-in-verse) type so you can add more commands later by creating more subclasses. With an `enum` type, you cannot change it or add more values to the enum after the initial published version of the project, so the `enum` type is better when you don't expect your data to change after you publish your project.

The following is the complete code for the command implementation.

Verse

    # This file contains the data representation of all the commands that the NPC can receive
    # and utilities for the data to help with debugging and troubleshooting issues.
    
    # Each type of command that the NPC can perform will be an instance of this class.
    # The class has the unique specifier to make instances of the class comparable.
    # The class has the computes specifier to be able to instantiate it at module-scope.
    # The class has the abstract specifier so it cannot be instantiated directly, and
    # requires subclasses to implement any non-initialized functions, like DebugString().
    command := class&lt;computes&gt;&lt;unique&gt;&lt;abstract&gt;:
        DebugString():string
    

Expand codeCopy full snippet(39 lines long)

Next Step
---------

We've defined the commands and shown how to add as many as you want.

In the next step, learn how these commands are used in the UI and how to add a custom UI for controlling the character.

[

![5. Controlling the NPC with UI](https://uefn-docs.yuzulabs.dev/community/api/documentation/image/88690df5-0ea4-459a-8142-896f2f202c8a?resizing_type=fit&width=640&height=640)

5\. Controlling the NPC with UI

Learn how to create and update a custom, dynamic in-game UI using Verse.





](https://uefn-docs.yuzulabs.dev/documentation/en-us/fortnite/verse-starter-05-controlling-the-npc-with-ui-in-unreal-editor-for-fortnite)

*   [verse](https://uefn-docs.yuzulabs.dev/community/search?query=verse)

* * *

Ask questions and help your peers [Developer Forums](https://forums.unrealengine.com/categories?tag=fortnite)

Write your own tutorials or read those from others [Learning Library](https://uefn-docs.yuzulabs.dev/community/fortnite/learning)

On this page

*   [Next Step](/documentation/en-us/fortnite/verse-starter-04-representing-command-data-for-in-unreal-editor-for-fortnite#next-step)</pre>
</body>
</html>