Sending variables to Ink

After a last-minute pivot from ChoiceScript to Ink for an IntroComp entry, I’m picking up the language pretty quickly (it’s a very intuitive system!), but running into one roadblock.

In the current ChoiceScript code, there’s a section that asks the player to enter a name for their character if they don’t like any of the suggested ones.

I know that Ink can’t handle this sort of freeform input by default. But since I’m going to be using the web runner, it seems easy enough to add to the HTML. At its simplest, I just need to emit an <input type="text"> as part of the story text, and add some JavaScript to the page to do something with its value.

The question is, how do I get that value back into Ink? In other words, how do I take a value from a JavaScript variable in the web runner, and put it into an Ink variable?


The documentation suggests that it’d be story.variablesState.playerName = "Fred" or something like that. I haven’t tested it, but generally the JavaScript implementation does work the same as the C# one…


You can also call an external JS function from ink. That function could read the input and return the value.


Also, if you want simplicity, there’s prompt().


EXTERNAL prompt(message, default)
~ temp name = prompt("your name?", "john")


story.BindExternalFunction("prompt", prompt);