Move a story from Twine
Move a SugarCube or Harlowe story to IFLoom, with one passage converted side by side and the differences to plan for.
Use this when you have a story written in Twine's SugarCube or Harlowe and want it in IFLoom. Make a game first, as Create a game shows. The Twine phrasebook maps each macro and special passage, and this page converts a whole passage.
Still deciding whether to move? IFLoom and Twine compares the two, with where Twine is the better choice.
Decide where each passage goes
A Twine story is one file of passages, and an IFLoom game is a few files that each export Content. Sort the passages into the layout every template starts with:
StoryInitand the variables every passage uses go insrc/world/, a file per kind:stats.ts,things.ts, andcast.tsfor the people.- The passages of one place, chapter or character go in one file in
src/story/, such asstory/cafe.ts, with their words. - Passages tagged
widget, and the Story JavaScript, go insrc/rules.tsas the game's own code. - The story's title goes in
src/game.ts, the game module. The start passage becomesintroScene, in the content that holds that scene.
Organise your game's files has the whole layout.
Convert a passage
This café passage in SugarCube shows a line when the player is short of money, and offers a coffee that costs 3 coins:
:: Cafe
Ava looks up from the till. "The usual?"
<<if $coins lt 3>>Your pockets feel light.<</if>>
<<if $coins gte 3>>
<<link "Buy a coffee (3 coins)" "Street">><<set $coins -= 3>><<set $hadCoffee to true>><</link>>
<<else>>
You can't afford a coffee.
<</if>>
[[Head back out|Street]]Convert it in four steps:
- Declare each variable that holds a number as a stat in
src/world/stats.ts, with its start and label.$coinsbecomes the statcoins. - Make the passage a scene in
src/story/cafe.ts. Each line of text becomes atext()block, and a line inside<<if>>takes the condition as itswhen. - Make each link a choice. A link inside
<<if>>becomes a choice withblocked, which keeps the button on screen with its reason. Each<<set>>becomes an effect, and a true/false variable such as$hadCoffeebecomes a key in the kv store. - Make the link's target the choice's last effect,
{ scene: 'street' }.
The result, kept in one file here to stay short:
import { text, type Content } from '@ifloom/engine'
export const cafe: Content = {
introScene: 'cafe',
stats: [{ id: 'coins', label: 'Coins', start: 5, max: 999, spendable: true, format: '{n} coins' }],
scenes: [
{
id: 'cafe',
title: 'The Corner Café',
body: [text('Ava looks up from the till. "The usual?"'), text('Your pockets feel light.', { when: { stat: 'coins', lt: 3 } })],
choices: [
{
id: 'coffee',
label: 'Buy a coffee',
blocked: [{ when: { stat: 'coins', lt: 3 }, reason: 'You need 3 coins.' }],
effects: [{ stat: 'coins', by: -3 }, { kv: 'hadCoffee', to: true }, { scene: 'street' }],
},
{ id: 'leave', label: 'Head back out', effects: [{ scene: 'street' }] },
],
},
{ id: 'street', title: 'The high street', body: [text('The high street, busy with the market.')], choices: [] },
],
}Leave the price out of the label. coins is spendable, so the UI works the price out from the choice's effects and shows Buy a coffee (3 coins) itself.
Plan for the differences
Four things in a Twine story need a different shape in IFLoom:
- HTML and JavaScript in prose. Prose is words with a small markup for speech, pictures, video and sound. Move styling to your UI's theme and CSS, and calculations to
rules. - Variables that hold objects. A stat holds a number, and a kv key holds a number, a string or
true/false. The state is the save and must survive being written as JSON, so model a list of things as entities. - Changing text after it shows. A choice changes the state, and the scene renders again from it. Replace
<<replace>>and similar macros with blocks whosewhenreads the state. - The Twine editor. Scenes are objects in
.tsfiles, which you edit in a code editor.
Check it worked
Run npm run check after each passage you convert. It reports a choice that goes to a scene nobody declared, a stat that doesn't exist, or a misspelt key, with the scene it's in:
cafe · scene cafe · goes to unknown scene "stret"It prints No problems. once every name resolves. Then run npm run dev and play the scene: the coffee button is refused with You need 3 coins. while the player has fewer than 3 coins.
For more, see:
- The Twine phrasebook, for every SugarCube and Harlowe macro.
- Scenes, Conditions and Effects.
- Differences from Twine, Ink and Ren'Py, for why IFLoom keeps rules out of the prose.
Last updated on
Run the examples from the repository
Try unreleased IFLoom code from a clone of the repository by playing the examples or making a game in or beside the checkout.
Write a flowing scene
Write a scene that reads on as the player chooses, with decisions partway through, jumps, a minigame in place and parts that fold away.