Skip to content

Instantly share code, notes, and snippets.

@robwhitaker
Last active September 22, 2022 05:02
Show Gist options
  • Save robwhitaker/64ccdef596b04ca3fd8852fbdee1f1a5 to your computer and use it in GitHub Desktop.
Save robwhitaker/64ccdef596b04ca3fd8852fbdee1f1a5 to your computer and use it in GitHub Desktop.
Setting up Tweego w/ SugarCube 2.20 & Sublime Text 2 / VSCode

Tweego Setup

Note:

  • 2020-02-24 - Several things have changed since I wrote this back in 2017. I suggest checking out AnotherEpigone's comment below before trying to follow this guide.

Downloading and installing Tweego

You can download Tweego from the (hard to find) Tweego page on the Motoslave website. Compiled executables are available for Windows, Mac, and Linux, or you can follow the link on that page to Bitbucket to compile it yourself from source (instructions on Bitbucket).

There is no installer. Once you download the executable, add it to your PATH and you're all set to use Tweego...

Sort of.

Installing story formats

Tweego doesn't actually come with any story formats, meaning you can't actually compile a project with just the executable. So download the format(s) you want (we'll be using SugarCube 2.20, which you can download here). For convenience, you should create a folder and keep your story formats in there.

Now, set the TWEEGO_PATH environment variable to the folder containing your story formats so Tweego knows where to find them.

There is a flag (-f or --format=) in Tweego that allows you to specify the storyformat you want to use as a command line parameter. If none is provided, it defaults to sugarcube-2. Sounds like what we want since we're using SugarCube 2.20, but it's not. And, at least for me, the command line flag didn't work.

So we're screwed, right?

Well, not quite. Turns out there is another environment variable (TWEEGO_FORMAT) which you can (and should) set which specifies the default story format Tweego will use. For SugarCube 2.20, we want to set it to SugarCube-2. Yeah, capitalization matters.

If you have other formats in your formats folder and want to know what they're called, use tweego --list-formats.

And that's it! You now have a working installation of Tweego with SugarCube 2.20 (or whatever format(s) you're using).

But wait, what about syntax highlighting?

If you're like me, you won't be happy until you can edit this in your text editor of choice with sweet, sweet syntax highlighting. In that regard, I can help you set it up in VSCode or Sublime Text and point you in the right direction for everything else.

Getting the language file

In all cases (probably), you'll want some sort of .tmlanguage file that provides syntax highlighting for .twee, .tw, and/or .tw2 files. Here are language files for twee and twee2. Both are designed for and have instructions for installation in Sublime Text, and both support SugarCube (though I prefer the former in that regard). The twee2 one adds support for the new story format, Harlowe.

If you use an editor other than Sublime or VSCode, you'll have to figure out how to get the .tmlanguage files installed there. Since I use VSCode, I'll explain how to set it up...

VSCode Syntax Highlighting

To get language highlighting working in VSCode, you need to turn the .tmlanguage file into an extension. Luckily, this is easy to do by following the intructions here regarding "New Language Support." You'll probably want to fill in .tw,.tw2,.twee for the file extension prompt.

Once you've followed those instructions and turned the .tmlanguage file into an extension, you'll want to go ahead and toss that extension into your extensions folder (usually ~/.vscode/extensions) and restart VSCode. When the editor opens again, you're syntax highlighting extension should be active.

@monyarm
Copy link

monyarm commented Sep 15, 2018

Thank you, i was looking for how to add Syntax Highlighting for Twee2

@AnotherEpigone
Copy link

This was a great guide. It looks like there are a couple things that have changed and are now a bit easier to set up.

  1. Tweego downloads now come with the standard set of story formats (harlowe, paperthin, snowman and sugarcube). It seems to know where to find them if you just extract the zip and run, so you no longer need to set the TWEEGO_PATH environment variable. I did have to download a new version of sugarcube 2 and replace the one they provided. It also correctly defaulted to sugarcube 2 for me without having the TWEEGO_FORMAT environment variable set.

  2. Syntax highlighting in VS Code has also become much easier. Open a .twee file, and it will instantly pop up a message pointing you to a free extension in the marketplace for .twee files. One-click install and it works.

@robwhitaker
Copy link
Author

@AnotherEpigone Thanks for the update! I stopped using Tweego quite a while ago, so I'm not up-to-date on recent developments, but I'm glad the guide is still helpful. I've added a link to your comment at the top of the guide for people to refer to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment