Skip to content

Quickstart

eugeniusfox edited this page Aug 15, 2016 · 2 revisions

First, write the script:

# The greatest story ever told

label start:
    her "Listen to me!"

    menu:
        "Shut up!":
            her "You meanie!"
            SomeAction
        "Sorry. You were saying?" if SomeCondition:
            her "Eh? Uh? Who are you, what am I doing here??"
            me "I'm just a disembodied string of characters."

    jump the_end

label the_end:
    me "That's all folks!"

See Script syntax for an overview of the syntax.

Then, load and run the script:

var path = @"path/to/script.rpy";
var script = Script.FromSource(path);

// Provide a dictionary of the available actions
script.Actions = new Dictionary<string, Action>() {
    {"DoNothing", () => { }},
    {"SomeAction", () => { }}
}

// Provide a dictionary of the available conditions
script.Conditions = new Dictionary<string, Func<bool>>() {
    {"True", () => true},
    {"False", () => false},
    {"SomeCondition", () => (new Random()).Next(0, 9) >= 5}
};

// Bind delegates to placeholders in the script
script.Prime();

// Check that the script is correctly initialized and ready to run
script.Validate();

// Run the script
script.RunFromBeginning(
    OnMenu: menu => (new Random()).Next(menu.Count - 1),
    OnLine: line => Console.WriteLine(line.ToString()));

See Running the script for further information.

In Unity3D, you'd start a coroutine instead:

StartCoroutine(script.GetCurrentEnumerator(OnLine, SelectChoice, OnChoiceSelected, OnReturn));

See Unity3D integration for further information.