githubEdit

Instructions

Introduction

The Instructions property is an exposed InstructionList which the InstructionManager will check and execute if according to the TimeManager'sarrow-up-right CurrentTime property. Instructions which do not necessarily belong to an instance, or which are to be executed on an object which does not implement the IInstructablearrow-up-right interface can be added to the InstructionManager's Instructions property for automatic execution.

Code Example

Instructions can be directly added or removed from the InstructionManager.Instructions list:

// Calls the EndGame method in 10 seconds:
var delegateInstruction = new DelegateInstruction( 
    () => EndGame(), 
    TimeManager.CurrentTime + 10);

InstructionManager.Instructions.Add(delegateInstruction);

Execution Details

The InstructionManager will execute Instructions if the InstructionManager's IsExecutingInstructions property is true (default). The InstructionManager will automatically check the time of instructions and execute them.

Common Usage

Instructionsarrow-up-right are a common part of the FlatRedBall game engine, and many FlatRedBall objects implement the IInstructablearrow-up-right interface. If an instruction is instantiated which should operate on an IInstructablearrow-up-right, then the instruction should be added to the IInstructable'sarrow-up-right Instructions property. This suggests that the IInstructablearrow-up-right "owns" the instructions which will operate on it. Having each IInstructablearrow-up-right contain Instructionsarrow-up-right which will operate on it can help improve debugging. Some objects, such as Screensarrow-up-right do not implement the IInstructablearrow-up-right interface, or are not automatically managed by a manager. It is common practice to place Instructionsarrow-up-right which will operate on these objects in the InstructionManager's Instructions list. Instructions in this list will also automatically be executed, and provide a centralized, easy to use list for instructions. However, in general, use the Instructions property for individual objects if available before using the InstructionManager's Instructions list.

Clearing all Instructions

You can clear all instructions by simply calling the Clear method on the Instructions object:

Last updated

Was this helpful?