0 votes
by (160 points)
I used Twine a while back (I believe Harlowe), back in the forum days, and I ended up stopping because I'd dug myself into a deep hole trying to force object-oriented stuff into Twine.  Nothing too complex, I was just trying to track variables for changes in the character's state, sneak in some functions for changing them safely, simple language parsing so sentences get adjusted based on character and game state.. but it just got really messy over time.  So I'm curious (and not seeing this in the forums)..  Twine is built on Python I believe (suggested by https://pypi.python.org/pypi/twine )... is it possible to call out To Python stuff?  And have that handle complex logic while letting Twine focus on what it does best - display, context-switching, saving simple variables, etc?

2 Answers

+1 vote
by (159k points)
selected by
 
Best answer

built on Python ... suggested by (URL)

The Python package you linked to is unrelated to the applications or concepts found on the Twinery related websites.

Background
a. The Twine 1.x application is written using Python.
b. The web-browser base Twine 2.x application is written using HTML / CSS / Javascript.
c. The install-able based Twine 2.x application combines point B with the NW.JS framework.
d. The Story Formats are written using HTML / CSS / Javascript.
e. Web-browsers don't naively support Python as a scripting language the same way they support Java-script.
f. The Twine (1.x or 2.x) application only handles the editing of Passages and the combining of Passages with a Story Format to create a Story HTML file.
g. The Story Format is responsible for everything else.

is it possible to call out To Python stuff...

1. If you are asking if you can use Python to extend the functionality of the Twine 1.x application to alter the contents of Passages before they are combined together with a Story Format to create a Story HTML file.

Yes, just fork the Twine 1.x repository and add whatever functionality you want to your own version of the Twine 1.x application.

2. If you are asking if you can call Python code from a Story HTML file being run in a web-browser

Technically Yes, and the Python Web Browser Programming page explains some of the possible methods.

0 votes
by (63.1k points)

That link is for something else that's also named Twine. 

The Twine 1 editor is built in Python. Version 2 is 100% built on web technologies, as far as I know. Regardless, even in Twine 1, the compiled file contains no Python code itself; the story you generate is an html file. 

It's probably possible to use Twine as a component in some project that uses another language, but there's really no native support in Twine for this. 

If you want to do the things you described but don't want to use macros or TwineScript (nothing you described seems impossible in Twine) then you should probably try a different story format, like SugarCube or Snowman, as Harlowe doesn't really have any JavaScript API. 

by (160 points)
Got it, thank you.  (and yea, it wasn't impossible, it just got really convoluted to hide functions in calls, then call back to where they were being used, and the way each variable had to be tracked.. was just ew.  Thank you, good to know :)
...