Ways to use a single Twine passage repeatedly

- Posted in Coding by

We can use a passage repeatedly by incrementing a story variable that is used with a <<switch>> to select what the passage should display.

The way I do this is to define a widget like so (be sure the passage in which you define the following widget has a widget tag:

<<widget lb>>
<<goto $p>>
<</widget>>

Then, in special passage PassageDone I put this code:

<<set $p to passage()>>

The above sets story variable $p to the name of the most recently rendered passage.

Using the above, we can then do the following in the passage we want to repeatedly use (assume the passage name is MyPsg):

<<switch visited()>>
<<case 1>>
     Case 1 text goes <<link here>><<lb>><</link>>.
<<case 2>>
     Case 2 text goes <<link here>><<lb>><</link>>.
<<case 3>>
     Case 3 text goes <<link here>><<lb>><</link>>.
<<default>>
     Text for after the third passage visit.
<</switch>>

Here's another way you can accomplish this (I prefer the method used above):

<span id="start">
This text will be displayed when the passage is first loaded.
</span>

<<set _count to 0>>

<<link "Continue">>
  <<set _count++>>
  <<replace "#start">>
    <<switch _count>>
      <<case 1>>
      This text will be displayed when the "Continue" Link is clicked the first time.
      <<case 2>>
      This text will be displayed when the "Continue" Link is clicked the second time.
      <<case 3>>
      This text will be displayed when the "Continue" Link is clicked the third time.
    <</switch>>
  <</replace>>
<</link>>

Sunday May 18th Update on my Twine WIP

- Posted in Coding by

 work in progress image'

On 5/19/2025, I added about another 5Kb, a mixture of prose/twinescript.


As of 18th May, 2025: I gave updates previously the 16th and the 17th of this month. Progress is strong on my current WIP, A Campfire Tale. This evening, I broke 10,000 words and we're at 48 passages. A lot of those passages contain considerable prose, twinescript, or a mixture of both.

This afternoon and evening I've spent time fleshing out inventory manipulation. It's semi-puzzlely in that you most combine some items to create new items, and then must make use of some of those new items to escape the initial chamber in which you were deposited after the alien ship tractor-beamed you.

Altogether today, I increased the game contents by about 10 Kb.

A Campfire Tale as of Mid-May 2025

- Posted in Coding by

I'm at 41 passages on my Twine WIP, "A Campfire Tale", and currently I'm spending some time building an Action/Object system in passage EscapeFrom.

Here is some code from that passage. To date, I've got it working to show appropriate long descriptions for objects that I select with a hyperlink click:

Future Twine Titles

- Posted in Coding by

Adrift Until A Tad Bit Informed
At My Feet In Ashes Lay
From Coxwain To Captain
I Write In Twine Now
Nothing Broken In Heaven
Only In Extremis
That Which Crowned Our Past
The Affection I Once Bore You
Unexpected Benefits of the Apocalypse

Recipe for an Inventory system in Twine Sugarcube

- Posted in Coding by

The anatomy of an inventory system: (a) the arbitrarily long return function (b) creating the YourInventory passage with a [noreturn] tag (c) creating the StoryMenu passage so we can link to YourInventory (d) give the player some starting inventory items (optional)


(a) The Arbitrarily Long Return function

/* Trigger the following code at the start of navigation to a new passage. */
$(document).on(":passagestart", function (event) {
        /* Make sure the current passage doesn't have a "noreturn" tag. */
        if (!tags().includes("noreturn")) {
                /* If it doesn't, then set $return to the current passage name. */
                State.variables.return = passage();
        }
});

In case the above inline code doesn't display correctly, or breaks at some point, here is the Github gist of the above Arbitrarily Long Return function.


Next I provide the code for the YourInventory passage and the two widgets it makes use of.

the passage code:

<<nobr>>
<<if $inventory eq undefined>>
Inventory is undefined
<<else>>
<<InventoryItemCount>>
<<InventoryItemListing>>
<</if>>
<</nobr>>

and the code for the two widgets:

<<widget "InventoryItemCount">>
/* This widget prints a message to the browser window telling the player how many items are in her inventory. I still need to add the Twinescript needed to accomplish this -- but all I have to do is copy/paste it from the YourInventory passage. */ 
<<nobr>>Your inventory contains:
<<if $inventory.length lt 1>>
nothing
<<elseif $inventory.length eq 1>>
1 item
<<else>>
<<= $inventory.length>> items
<</if>>
<</nobr>><</widget>>

<<widget "InventoryItemListing">>
/* This widget prints the inventory's items,
one per line */
<<nobr>><<if $inventory.length eq 1>>
$inventory[0]
<</if>>
<<if $inventory.length gt 1>>
<<= $inventory.join(`<br>`)>><br>
<</if>>
<</nobr>><</widget>>

And, against future need, here is a gist of the above passage code and code for the two widgets.

One option for making the YourInventory passage available during play is to add the following line to special passage StoryMenu:

<<link "Inventory">><<goto YourInventory>><</link>>

One way to give the player some beginning inventory items would be to set them in special passage StoryInit:

<<set $inventory to ['a canteen', 'a pocket knife', 'a handkerchief', 'a flashlight', 'a revolver']>>

I found some old Harlowe example code for Twine

- Posted in Coding by


I found my old Harlowe examples for Twine, and threw them up on a couple of servers.

Change font face and size in Twine with Sugarcue

- Posted in Coding by

Thanks to Josh Grams, I now understand how to set up players/readers of my twines with the ability to change font face and font size. Below I link to the scripts you need to drop, respectively, into the javascript and stylesheet special passages in the desktop Twine 2.10.0 app. Here is the zip containing the needed JS and CSS. I host a demo of this here and here, and mention it in my Twine Tidbits on the local copy of my blog.

Run your own website-hosted Twine dev tool

- Posted in Coding by

You can run your own copy of the Twine development tool, either by hosting it on your website or by running it in XAMPP. For example, here it is running on my own website. And here is the 4 Mb download if you want a copy. I also have a copy here on my Onedrive.

Work project as of 28th March 2025

- Posted in Coding by

Below is a compressed arrangement of the nodes that make up my current Twine project for my employer. A downloadable zip archive of these images at full size is here. The following is an Osage version:

Perhaps you'd prefer the twopi version below;

Below is the neato version:

And finally, below I show the fdp version:

Page 1 of 3