> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/flatredball/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/flatredball/api/flatredball/instructions/iinstructable.md).

# IInstructable

### Introduction

The IInstructable interface specifies that an object can store instructions in an InstructionList. Most FlatRedBall classes which implement the IInstructable interface have managers which handle [Instruction](https://github.com/flatredball/FlatRedBallDocs/blob/main/frb/docs/index.php) execution. [Instructions](https://github.com/flatredball/FlatRedBallDocs/blob/main/frb/docs/index.php) allow the setting of properties at a predetermined time in the future without any explicit management.

### Using Instructions

The FlatRedBall Engine provides a generic [Instruction](https://github.com/flatredball/FlatRedBallDocs/blob/main/frb/docs/index.php) which can be used to set any property. The following code moves a Sprite in a square when the space bar is pushed.

```
// Add this using statement
using FlatRedBall.Instructions;

// Declare the Sprite instance at class scope
Sprite sprite;

// Replace Initialize with the following:
protected override void Initialize()
{
    FlatRedBallServices.InitializeFlatRedBall(this, this.graphics);

    base.Initialize();

    sprite = SpriteManager.AddSprite("redball.bmp");
}

// Replace Update with the following.
protected override void Update(GameTime gameTime)
{
    FlatRedBallServices.Update(gameTime);

    if (InputManager.Keyboard.KeyPushed(Keys.Space) && 
        sprite.Instructions.Count == 0)
    {
        float secondsToTake = 4.0f;
        float squareWidth = 10;

        float velocity = squareWidth * 4.0f / secondsToTake;

        // Move right.
        sprite.Instructions.Add(
            new Instruction<Sprite, float>(
                sprite, "XVelocity", velocity, 
                TimeManager.CurrentTime + 0));

        // Stop moving to the right.
        sprite.Instructions.Add(
            new Instruction<Sprite, float>(
                sprite, "XVelocity", 0, 
                TimeManager.CurrentTime + secondsToTake / 4.0f));
        // Move down.
        sprite.Instructions.Add(
            new Instruction<Sprite, float>(
                sprite, "YVelocity", -velocity, 
                TimeManager.CurrentTime + secondsToTake / 4.0f));

        // Stop moving down.
        sprite.Instructions.Add(
            new Instruction<Sprite, float>(
                sprite, "YVelocity", 0, 
                TimeManager.CurrentTime + 2 * secondsToTake / 4.0f));
        // Move left.
        sprite.Instructions.Add(
            new Instruction<Sprite, float>(
                sprite, "XVelocity", -velocity, 
                TimeManager.CurrentTime + 2 * secondsToTake / 4.0f));

        // Stop moving left;
        sprite.Instructions.Add(
            new Instruction<Sprite, float>(
                sprite, "XVelocity", 0, 
                TimeManager.CurrentTime + 3 * secondsToTake / 4.0f));
        // Move up.
        sprite.Instructions.Add(
            new Instruction<Sprite, float>(
                sprite, "YVelocity", velocity, 
                TimeManager.CurrentTime + 3 * secondsToTake / 4.0f));

        // Stop moving up at the end.
        sprite.Instructions.Add(
            new Instruction<Sprite, float>(
                sprite, "YVelocity", 0, 
                TimeManager.CurrentTime + 4 * secondsToTake / 4.0f));
    }

    base.Update(gameTime);
}
```

### Calling instructions on the object that will be modified

Instructions must be called on the object that will be modified. You cannot use the "dot" operator to set properties of embedded items. For example, the following is not valid:

```
// assume myScene is a valid Scene
Instruction instructionToExecute = 
    new Instruction<Scene, float>(   // NO NO NO - this is setting a property on a Sprite, not Scene
                myScene, 
                "Sprites[0].YVelocity", // NO NO NO - No [] or . allowed
                velocityToSet, 
                timeToExecuteAt);
```

Instead you should pass the instance as the first argument and have the property as the second argument:

```
Instruction instructionToExecute = 
    new Instruction<Sprite, float>(   
                myScene.Sprites[0], 
                "YVelocity",
                velocityToSet, 
                timeToExecuteAt);
```

### InstructionManager

The [InstructionManager](https://github.com/flatredball/FlatRedBallDocs/blob/main/frb/docs/index.php) provides methods for performing common behavior on different objects. See the [InstructionManager wiki entry](https://github.com/flatredball/FlatRedBallDocs/blob/main/frb/docs/index.php) for more information.

### IInstructable Members

* [FlatRedBall.Instructions.IInstructable.Call](https://github.com/flatredball/FlatRedBallDocs/blob/main/frb/docs/index.php)
* [FlatRedBall.Instructions.IInstructable.Instructions](https://github.com/flatredball/FlatRedBallDocs/blob/main/frb/docs/index.php)
* [FlatRedBall.Instructions.IInstructable.Set](https://github.com/flatredball/FlatRedBallDocs/blob/main/frb/docs/index.php)

Did this article leave any questions unanswered? Post any question in our [forums](https://github.com/flatredball/FlatRedBallDocs/blob/main/frb/forum.md) for a rapid response.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://docs.flatredball.com/flatredball/api/flatredball/instructions/iinstructable.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.
