Converting Twine source to .rpy files

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
saguaro
Miko-Class Veteran
Posts: 560
Joined: Sun Feb 12, 2012 9:17 am
Completed: Locked-In, Sunrise, The Censor
Organization: Lucky Special Games
itch: saguarofoo
Location: USA
Contact:

Converting Twine source to .rpy files

#1 Post by saguaro »

I recently became interested in using Twine to storyboard so I could take advantage of node maps for branching stories. This tool is for building a story in Twine with Ren'py code (except using Twine's macros for jump/call/etc. to utilize the node map), testing as needed, then exporting to an .rpy with the macros converted to the Ren'py equivalents. See the examples in the .zip.

twine2rpy converts PassageTitle to label, internalLinks to jump, <<display>> to call, <<choice>> to jump, <<set>>, <<print>>, and if blocks. It doesn't convert multiple variable assignment or multiple conditions (using ;) or ternary operators.

Run the script from the command line: twine2rpy.py source.txt

The .zip includes a sample .tws, .txt, and .rpy.

Update: v 1.1 replaces tabs with 4 spaces. Ren'Py doesn't like tabs. If you already converted using the previous version you can fix it yourself by using your editor's replace function to replace "\t" with four spaces (check the regular expression field).
Attachments
twine2rpy-1.1.zip
(4.78 KiB) Downloaded 486 times
Last edited by saguaro on Thu Mar 07, 2013 1:13 pm, edited 3 times in total.

User avatar
chronodekar
Newbie
Posts: 3
Joined: Wed Feb 27, 2013 10:46 am
Contact:

Re: Converting Twine source to .rpy files

#2 Post by chronodekar »

Haven't checked out your tool, but Twine looks interesting. Thanks for sharing !

-chronodekar

User avatar
Kessie
Regular
Posts: 140
Joined: Wed Aug 15, 2012 11:47 am
Contact:

Re: Converting Twine source to .rpy files

#3 Post by Kessie »

Thanks heaps for sharing! :)

I just know a little twine is going to help me go a long way from my usually disorganised script writing xD.
Avatar made by xSugar-ZooZoo

User avatar
saguaro
Miko-Class Veteran
Posts: 560
Joined: Sun Feb 12, 2012 9:17 am
Completed: Locked-In, Sunrise, The Censor
Organization: Lucky Special Games
itch: saguarofoo
Location: USA
Contact:

Re: Converting Twine source to .rpy files

#4 Post by saguaro »

Yeah, I think it's definitely helping me stay organized on my current project.

The only two issues I've encountered so far are copy-pasting from a word processor without converting to utf-8 first (Twine won't export non-Unicode, so you have to find/replace) and the fact that Twine exports the nodes left-right top-bottom, so you need to set up nodes that way if you want the exported labels to have any kind of order.

User avatar
Kessie
Regular
Posts: 140
Joined: Wed Aug 15, 2012 11:47 am
Contact:

Re: Converting Twine source to .rpy files

#5 Post by Kessie »

Oh I see :o
Thanks for explaining that because I was considering copy and pasting and wouldn't have figured out those technical issues ^^;
Appreciate it :D
Avatar made by xSugar-ZooZoo

monstergrin
Newbie
Posts: 1
Joined: Sun Jun 19, 2016 4:12 pm
Contact:

Re: Converting Twine source to .rpy files

#6 Post by monstergrin »

This seems like a terrific tool, but I can't get it to work! Is it still supported?

User avatar
jesusalva
Regular
Posts: 88
Joined: Mon Jul 22, 2013 5:05 pm
Organization: Software in Public Interest, Inc.
IRC Nick: jesusalva
Github: pazkero
itch: tmw2
Location: Brazil
Discord: Jesusalva#4449
Contact:

Re: Converting Twine source to .rpy files

#7 Post by jesusalva »

monstergrin wrote: Sun Jun 19, 2016 4:14 pm This seems like a terrific tool, but I can't get it to work! Is it still supported?
In December 2014, Twine released a new version, Twine 2.

This is the version which Twine gives you by default, and it only exports HTML documents.
This script was made for Twine 1, which is still available to download as of writing, but doesn't receive updates since 2016 (according to github).


You can try Twine 1 to make use of this script at your own risk.

A small experiment I did:
I actually wrote in about 40 minutes a quick python script which will read the HTML file and extract the most relevant tidbits from it.

It is not meant for production; Currently it can only make simple narrator texts and simple menus. (If you go past page 2 of Twine Quickstart this script will give up).

Do note that I was only tinkering to see if it would be possible to make such tool (the answer is: Yes, it is possible), so I did not even bother to try it on Python3. (So yep, another short-lived utility script).
twine2rpy_2.py
A simple script for simple things
(4.8 KiB) Downloaded 71 times
Jesusaves/Jesusalva

prestristan
Regular
Posts: 25
Joined: Sat Apr 11, 2020 1:28 pm
Contact:

Re: Converting Twine source to .rpy files

#8 Post by prestristan »

Wow I didn't know Twine can do that :O
All I know is that Twine can only export to .html Ha HA
Thanks for sharing! @saguaro

Post Reply

Who is online

Users browsing this forum: No registered users