Tutorials
Your first project
In this tutorial you write a small story in .osf, check it, play it, and convert it into OSF resources. It takes four files.
Install the CLI
On macOS or Linux, install osf with one command. For Windows and other options, see Install.
$ curl -fsSL https://openstoryfoundation.com/install.sh | shWrite the project
A project is a folder. Every .osf file in it is read, and which file a block lives in does not matter. Start with the Versions block, which pins the language and plugin versions:
Versions {
language = "1"
story = "v1"
dialogue = "v1"
}Then the story itself, with one variable:
Story my_story {
name = "My Story"
start = Dialogue.intro
}
Variable has_key: Boolean = falseCharacter guard {
name = "Guard"
}And the dialogue. The guard asks a question; one answer leads on and sets has_key, the other ends the dialogue:
Dialogue intro {
Node gate {
speaker: guard
text: "Halt! Who goes there?"
Option friend {
text: "A friend."
set: { has_key: true }
next: let_in
}
Option leave {
text: "Nobody. Bye."
}
}
Node let_in {
speaker: guard
text: "Then take this key, {{ Character.guard }} trusts you."
}
}Check it
osf fmt rewrites files in the standard formatting; with -check it only reports, and exits with status 3 when a file would change. osf validate checks the whole project:
$ osf fmt -check my-story
$ osf validate my-story
Success! The project is valid (1 dialogue, 1 character, 1 variable, 6 texts).Mistakes are reported with the file, line, column and a stable error code; every code is listed in docs/diagnostics.md. Here next points at a node that does not exist:
$ osf validate my-story
my-story/intro.osf:9:13: error: OSF113 Node gate, Option friend: next: node "let_inn" does not exist in Dialogue intro; did you mean "let_in"?
my-story/intro.osf:17:3: warning: OSF900 Node let_in in Dialogue intro is never reached
1 error, 1 warning.Play it
osf play runs the story in the terminal, the way Playing a dialogue defines it. Type the number of an option at the > prompt; variable changes are shown in brackets:
$ osf play my-story
== Dialogue intro
Guard: Halt! Who goes there?
1. A friend.
2. Nobody. Bye.
> 1
[set has_key = true]
Guard: Then take this key, Guard trusts you.
== Endosf play -coverage walks every path instead, and reports dead ends, options that no path can show, and loops with no exit:
$ osf play -coverage my-story
== Coverage from Dialogue intro
intro: 2/2 nodes reached
2 states, 2 endings
== No findingsConvert it
osf convert validates, then writes one JSON resource per Story, Character, Document, Variable and Dialogue into my-story-json/, next to the project. -o yaml writes YAML instead, and -out picks another folder:
$ osf convert my-story
Wrote json: 4 files in my-story-json (1 dialogue, 1 character, 1 variable, 6 texts).my-story-json/
guard.json
intro.json
story.json
variables/has_key.jsonEach file is one resource, described on its page in the format reference. osf convert -o osf goes the other way and turns JSON or YAML resources back into .osf files. Next, build a dialogue player that plays this story in your own code.