Show / Hide Table of Contents

    Command Actions

    All actions are under the QFSW.QC.Actions namespace

    The actions system allows you to write powerful and interactive commands that can suspend, similar to coroutines.

    To create a command using actions, simply make your command return either IEnumerator<ICommandAction> or IEnumerable<ICommandAction>. Next, yield return the action you wish to use.

    See here for creating your own custom actions.

    Examples

    Printing Values

    The following example prints a 3 second countdown timer.

    using QFSW.QC;
    using QFSW.QC.Actions;
    using System.Collections.Generic;
    ...
    
    [Command("countdown")]
    public static IEnumerator<ICommandAction> Countdown()
    {
        for (int i = 3; i > 0; i--)
        {
            yield return new Value(i);
            yield return new WaitRealtime(1);
        }
    
        yield return new Value("Countdown over!");
    }
    

    Reading Input

    The following example waits for the user to enter a key, then displays it to the console

    using QFSW.QC;
    using QFSW.QC.Actions;
    using System.Collections.Generic;
    ...
    
    [Command("read-key")]
    public static IEnumerator<ICommandAction> ReadKey()
    {
        KeyCode key = default;
        yield return new GetKey(k => key = k);
        yield return new Value(key);
    }
    

    Presenting Choices

    The following example has the user select a choice from a list of consoles

    using QFSW.QC;
    using QFSW.QC.Actions;
    using System.Collections.Generic;
    ...
    
    [Command("choice")]
    public static IEnumerator<ICommandAction> Choice()
    {
        string[] consoles = {"PS4", "Xbox", "Switch"};
        string selectedConsole = default;
    
        yield return new Value("Pick a console");
        yield return new Choice<string>(consoles, s => selectedConsole = s);
    
        yield return new Typewriter($"You picked {selectedConsole}.");
    }
    

    Included Actions

    Action Description
    ReadLine Gets the next line of text entered into the console as a user response
    ReadValue<T> Gets the next line of text entered into the console as a user response parsed to the type T
    Wait Waits for the given amount of seconds using scaled time
    WaitRealtime Waits for the given amount of seconds using real time
    WaitWhile Waits while the given condition is met
    WaitUntil Waits until the given condition is met
    WaitFrame Waits until the next frame
    WaitKey Waits until the given key is pressed
    Value Serializes and logs a value to the console
    RemoveLog Removes the most recent log from the console
    GetKey Waits for any key to be pressed and returns the key via the given delegate
    GetContext Gets the ActionContext that the command is currently being invoked on.
    Composite Combines a sequence of actions into a single action
    Choice<T> Give the user a selection of choices which can be made by using the arrow keys and enter key
    Typewriter Gradually types a message to the console
    Async, Async<T> Converts an async Task into an action
    Custom Custom action implemented via delegates
    Quantum Console by QFSW
    Back to top