# 3. Ink Language Essentials Part of [[Ink Narrative Integration]]. Back: [[2. Installing Ink for Unity 2.0]]. Next: [[4. Story Loop and UI Toolkit Presenter]]. > [!warning] Code not compiled in Unity > The Harbor Briefing `.ink` files were compiled with the compiler bundled in Ink Unity Integration 2.0.0 (format version 21). They have not been opened in Inky or play-tested in the Ink Player. This is not a complete Ink language manual. It is the subset you need to write a conversation that Unity can run, and to read the Harbor Briefing story the later parts hook up. inkle's writing tutorial (linked from **Help > Ink > Writing Tutorial...**) is the canonical language guide; if a construct is not shown here, look there before inventing syntax. [[Level Up! (Review)]] Level 3 still comes first: know what the harbormaster wants, what the player can do, and how the conversation ends. The language only delivers that. ## 3.1 The skeleton ``` === knot_name === Text the player sees. * "A one-time choice." Response. -> other_knot + "A sticky choice, offered every time we return." -> knot_name = stitch_name Text inside the knot. -> END ``` - **Knots** (`=== name ===`) are the named sections of the story. They are also the paths you will pass to `ChoosePathString` from an interactable. - **Stitches** (`= name`) are named subsections of the current knot. The path is `knot.stitch`. - **Diverts** (`-> target`) jump. `-> END` ends the story (no more content, no choices). - **One-time choices** start with `*`. Once picked, they disappear. - **Sticky choices** start with `+`. They remain available if the player comes back. - **Gathers** (`-`) mark the point where choice branches rejoin. This series mostly uses explicit diverts instead, which is easier to follow in a classroom. Conditional text and conditional choices use braces: ``` {has_permit: "The stamp is already on the ledger." | "You still need a permit."} * {has_permit} "I already have the permit." -> already_cleared ``` The choice with `{has_permit}` is only offered when that variable is true. ## 3.2 Variables, constants, and logic lines ``` CONST PLAYER_NAME = "Captain" VAR trust = 0 VAR has_permit = false ~ trust = trust + 1 ~ has_permit = true ``` `CONST` is immutable. `VAR` is a global in `story.variablesState`. A line that starts with `~` is a logic line: assignments, function calls, or `EXTERNAL` calls. `TEMP` (not used in the briefing) is a temporary in the current flow. Types you will actually put in variables: `int`, `float`, `bool`, `string`, and Ink **lists**. In C#, `variablesState["trust"]` comes back as `object` — typically `int`, `float`, `bool`, or `string`. Cast after you know the type you declared. Visit counts are built in. In ink, `{knot_name}` in a numeric context is how many times that knot has been seen. From C#, `story.state.VisitCountAtPathString("briefing")` is the official equivalent (package source, `StoryState`). ## 3.3 Tags A tag is a `#` at the end of a line, or on its own. After `Continue()`, the tags for that line are in `story.currentTags` (`List<string>`). Choice-specific tags are on `Choice.tags`. This series uses a small convention. Keep it boring and consistent: | Tag | Meaning | |---|---| | `speaker:Name` | Who is talking. The view shows this as the nameplate. | | `mood:warm` / `mood:stern` / … | A hook for portrait or VO, not parsed by Ink itself. | | `anim:look_up` | A hook for a one-shot animation. | | `voice:clipName` | Optional VO key, if you would rather tag than call `EXTERNAL`. | Global tags at the top of the master file (`# title: Harbor Briefing`) are available as `story.globalTags`. Knot-level tags can be queried with `story.TagsForContentAtPath("briefing")`. Both methods are on `Story` in the 2.0.0 runtime source. Do not overload tags with side effects that must be saved. A grant that must survive a reload belongs in a variable or in your inventory save, triggered from an `EXTERNAL` function. Tags are for presentation. ## 3.4 INCLUDE, lists, and EXTERNAL `INCLUDE HarborItems.ink` pulls another file into the master. The included file can declare `VAR`, `LIST`, `=== function ===`, and `EXTERNAL`s. An **external function** is declared in ink and bound in C# (part 5): ``` EXTERNAL GiveItem(itemName) ~ GiveItem("HarborPermit") ``` If you call it before `BindExternalFunction`, `Story` will error when you `ValidateExternalBindings` or when evaluation hits the call. Bind before the first `Continue()`. Ink **functions** (as opposed to externals) are knots declared with `=== function name ===` and called from ink or from C# via `EvaluateFunction`. The briefing includes `has_cleared`, which returns `has_permit`, so gameplay can ask the story a question without scraping text. ## 3.5 Harbor Briefing — `HarborItems.ink` Save as `Assets/InkNarrative/Stories/HarborItems.ink`. It is an INCLUDE, not a master, unless you tick **Compile As Master File**. ```ink // Shared item names and a helper the Unity side can EvaluateFunction. // Keep string ids identical to the inventory item ids in the C# catalog. === function item_permit === ~ return "HarborPermit" === function item_lantern === ~ return "SpareLantern" ``` ## 3.6 Harbor Briefing — `HarborBriefing.ink` Save as `Assets/InkNarrative/Stories/HarborBriefing.ink`. This is the master. ```ink # title: Harbor Briefing # author: class example CONST PLAYER_NAME = "Captain" VAR trust = 0 VAR has_permit = false VAR crates_offered = false EXTERNAL GiveItem(itemName) EXTERNAL PlayVoice(clipName) EXTERNAL SetQuestStage(questId, stage) INCLUDE HarborItems.ink -> briefing === briefing === The harbormaster looks up from a tide chart. # speaker:Harbormaster # mood:neutral # anim:look_up "You're the one shipping out at first light." # speaker:Harbormaster * "That's right. I need a berth and a permit." ~ trust = trust + 1 -> need_permit * "Depends who's asking." ~ trust = trust - 1 The harbormaster's mouth tightens. # speaker:Harbormaster # mood:wary "I'm the one who decides whether you leave this dock." # speaker:Harbormaster -> need_permit * {has_permit} "I already have the permit. Just point me to the berth." -> already_cleared === need_permit === {trust >= 1: "Then we can do this the easy way." # speaker:Harbormaster # mood:warm - else: "Then we do this by the book." # speaker:Harbormaster # mood:stern } -> permit_terms === permit_terms === "A harbor permit costs a ledger stamp, or you can run a favour." # speaker:Harbormaster + "I'll pay the stamp." ~ has_permit = true ~ GiveItem(item_permit()) ~ SetQuestStage("harbor_departure", 1) "Signed and sealed. Don't make me regret it." # speaker:Harbormaster -> gear_offer + "What kind of favour?" -> favour + "I'll come back later." "The tide won't wait." # speaker:Harbormaster -> END === favour === "A crate went missing from the east warehouse. Bring it back and I'll stamp the permit myself." # speaker:Harbormaster ~ SetQuestStage("missing_crate", 0) * "I'll find it." ~ trust = trust + 1 -> gear_offer * "That's not my problem." ~ trust = trust - 1 "Then it's the stamp or nothing." # speaker:Harbormaster -> permit_terms === gear_offer === {not crates_offered: ~ crates_offered = true {trust >= 1: "Take a spare lantern. The outer channel is dark." # speaker:Harbormaster ~ GiveItem(item_lantern()) } } The wind picks up off the water. # speaker:Narrator -> END === already_cleared === "Then you're wasting both our mornings." # speaker:Harbormaster # mood:dry -> END === function has_cleared === ~ return has_permit ``` A few things to notice, because they show up in the C# later: - The third briefing choice is hidden until `has_permit` is true, so a **second visit** after the stamp (part 6 will show how you re-enter the knot) takes the short path. - `GiveItem` and `SetQuestStage` run on the same logic lines as the variable changes. If you skip the UI mid-line, the runner in part 4 still **finishes the current `Continue()`**; it will not rewind an `EXTERNAL` that already ran. Design grants to be idempotent (giving the same permit twice should not duplicate it in [[Inventory Systems]]). - `permit_terms` uses sticky `+` choices so "What kind of favour?" can return and still offer the stamp. - `item_permit()` and `item_lantern()` live in the include so the string ids are defined once. ## 3.7 Check it in the Ink Player before writing C# Select `HarborBriefing.ink`, wait for the importer, click **Play in Ink Player**. Walk both the polite path (trust 1, permit, lantern) and the wary path (trust -1, favour, then stamp). Confirm the conditional "I already have the permit" choice stays hidden on a fresh play. If the file has errors, they appear on the asset and in the Console. Fix the `.ink` first. The C# in the next parts assumes this story compiles. > [!note] Inky desktop > Inky is a separate editor. I have not verified that whatever Inky build you have installed emits story format **21**, which is `inkVersionCurrent` in this package. For class work, prefer Unity's importer as the compiler of record. If you use Inky, play the same file in the Ink Player afterwards. Next: [[4. Story Loop and UI Toolkit Presenter]].