Passing variables into and out of Twine (using Java script)


I’m working on a game which cuts between interactive fiction (Twine) and procedural (HTML and JS) segments and I need a way to transfer variables between the files. Or, in other words, I need to know how to get variables from outside into a Twine file and then get variables back out again (after they’ve changed based on player choices). I’m a notoriously bad coder and really have no idea what I’m doing, so I don’t even really know where to start.

Also I’ve put Sugarcube as the format, but that’s mostly just because I imagine that will be the best one for this?

Look at using State.variables in Sugarcube. You can set them in JS or in your init file then use them throughout your story.

1 Like