How Tsumugi reads Ren’Py

Tsumugi reads your Ren’Py game the way Ren’Py does. Ren’Py’s script is its own language, so Tsumugi reads it as it is, and writes Ren’Py’s script for you. Nothing in your game is turned into Chatterbox.

Note

Ren’Py support is new in Tsumugi 1.3. This is its first version. If something doesn’t work, please tell us. Click Report a bug at the top right of this page, or use the contact page.

Finding the game

Tsumugi starts by itself in a folder with a game folder of .rpy files. The folder that holds game is the game. Open it with File › Open Folder….

To read the game again, run Tsumugi: Reload Game Project.

Story files

Story files are the .rpy files in game that have a label. Tsumugi leaves out:

  • the files in tl/ and libs/,
  • Ren’Py’s own gui.rpy, screens.rpy and options.rpy.

The Tsumugi sidebar lists them under Story files. Click one to open it in the Story Writer.

Ren’Py loads every .rpy file by itself, so a story file needs no line to load it. New story file… makes a new .rpy file in game, and that is all it needs.

Labels belong to the whole game. jump harbour reaches a label in any file, so two files can’t both have a label called harbour. The map shows jumps to labels in other files.

Opening as text

The first time a story file opens as text, Tsumugi asks once on this computer whether to open them in the Story Writer. Yes turns on the tsumugi.storyView.openRenpyStories setting. From then on, a story file opened as text opens again in the Story Writer.

Only story files do this. screens.rpy, options.rpy and your game’s code stay text. So do diffs, and the file Text opens beside the Story Writer.

How it reads the script

In your game In Tsumugi
label harbour: A node called harbour. Its lines are one step (4 spaces) in under it.
a "Welcome!" A line said by the character that a stands for.
a happy "Welcome!" The same line, with the emotion happy.
"The gate creaks." Narration: a line no character says.
menu: Options. Each line like "Look at the sea": under it is one option.
"Give the fish back" if courage >= 2: An option that shows only when its check is true.
A say line inside menu: The line shown with the options.
jump harbour Jump to
call shop Hop to
return Hop back, in a label a call led to. Anywhere else, return ends the game.
$ courage = 3, $ courage += 1 Changes a variable.
default courage = 0 A story variable and its starting value.
if, elif, else If, Else if and Else.
renpy.seen_label("harbour") Visited harbour, in a check.
$ answer = renpy.input("...") The player types into answer.
achievement.register("Brave"), achievement.grant("Brave") An unlock, and Unlock Brave.
# @tsumugi tags: Draft and # @tsumugi colour: blue, just above a label The node’s tags and colour. Ren’Py skips these lines.
  • Ren’Py starts the story at the node start (label start:). Your game needs nothing more for the story to begin.
  • A label that ends with no jump or return goes on into the next label in the file. The map draws an arrow to that one too, and the preview and Start here follow it.
  • A label stepped in inside another label’s block is not a node of its own. A jump to it links to the node that holds it.
  • An If ends where its indentation does. An empty case holds pass.

Characters and pictures

Your characters are the define lines in your game, like define a = Character("Ayumi", image="ayumi"). image names the character’s side images, which are their portraits.

Tsumugi finds pictures in game/images by their names, the way Ren’Py does:

Picture Is
side ayumi happy.png, or image side ayumi happy = ... Ayumi’s portrait for the emotion happy.
bg village gate.png, or image bg village gate = "gate.png" The area Village Gate. scene bg village gate is Change area to Village Gate.
item fish.png The item Fish.
unlock <id> The icon of the achievement <id>. Ren’Py’s own achievements have no icons.
image side ayumi wave: with pictures and pause lines, then repeat An animated picture. It plays in the preview.

Area art and items can start with a word of your own instead of bg and item, like background or bg_. Tsumugi reads the area art’s word from your scenes.

Ren’Py finds a picture in any folder in game/images. Settings > Your game picks the folders new portraits, items and area art go in, and the words their names start with. Set up this project guesses them, like images/side for portraits. New unlock icons go in images/unlocks.

Events and game code

Ren’Py needs nothing more to show your story. But items, health hearts and places on a map need game code.

Add Tsumugi’s game code, in the Tsumugi sidebar, writes game/tsumugi_game.rpy, with an inventory (give, take, check and count items), health hearts and places on a map. It also makes a placeholder map picture. It adds only what your game doesn’t have already, and shows what it will add before it changes anything.

A programmer can write their own instead. A Python function in an init python: block, with a line like # @tsumugi Give item {item} above it, is an event the writer can type.

Tsumugi also reads the text area’s size from gui.rpy: gui.dialogue_width, gui.text_size and gui.textbox_height. How many lines it shows can be changed in Settings > Game Text Area.

What it writes

The .rpy files Tsumugi keeps for itself are named game/tsumugi_….rpy, so you can tell them from your own.

What When
tsumugi.json, next to the game folder Set up this project, which asks first, and settings saved from the Story Writer.
A new .rpy file in game New story file…
game/tsumugi_variables.rpy The default line for each new variable.
game/tsumugi_characters.rpy A new character, when you type a new name on a line.
game/tsumugi_actions.rpy The function for each new event, for a programmer to fill in.
game/tsumugi_unlocks.rpy New achievements, like achievement.register("Brave").
game/tsumugi_animations.rpy Animated placeholders.
game/tsumugi_game.rpy Add Tsumugi’s game code.
game/tsumugi_start.rpy Start here. See Testing in Ren’Py.
Pictures in game/images Placeholders and your own pictures, named the way Ren’Py finds them. A file your game’s code names, or another picture shows, stays where it is.

In your story files, Tsumugi writes Ren’Py’s own statements, like jump, call, return, scene, menu: and $ lines.

It also changes your own files in these ways:

  • Renaming a node changes its label and every jump and call to it. Renaming a character changes the name in their define line. See Names and renaming.
  • Tidying sets each step of indentation to 4 spaces, and never moves a line to another block. A file with a tab in it, and your game’s code, are left alone.

Only in GameMaker

  • Colours for .gml, .yy and .yyp files. Tsumugi adds no colours for .rpy files. Ren’Py’s own VS Code extension has them.
  • The reload question. GameMaker asks to reload the project after Tsumugi changes it. Ren’Py reloads the script itself, with ⇧ R.

Next