Passing inventory across different Harlowe Twine stories

Twine Version: Harlowe 3.3.6
Hi everyone,

I am writing a collection of Twine narratives under the same domain name on my website that speak to each other. I have managed to pass variable numbers through in the URL successfully such as adrenaline being set to 2 for example.

However, I am trying to find a way to pass an Inventory across the different stories so that was the user has picked up will carry through even when it is a separate Twine story. I noticed a thread on this in relation to sugarcube but wanted to see if there was a Harlowe equivalent.

Currently I have the following in Javascript but can’t get it to speak to Harlowe. The website has this variable “?i=jo1” within it:

`

> set: $inventoryofthinkers to (a:))
<script>const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const i = urlParams.get('i');
$const inventory = i.split(",");

}
</script>

(print: $inventory)

(if: $inventory ("jo1")) [

(set: $inventoryofthinkers to $inventoryofthinkers + (a:"Jenny Odell")];

Any help would be massively appreciated! Does the above approach seem doable with some different code or is there a better approach? Thanks so much!

There are a number of syntax errors, in both the JavaScript and Harlowe Script, in your example.

Try the following instead…

(set: $inventoryofthinkers to (a:), $inventory to (a:))
<script>
	let queryString = window.location.search;
	let urlParams = new URLSearchParams(queryString);
	let i = urlParams.get('i');
	if (i) {
		$inventory = i.split(",");
	}
</script>

(if: $inventory contains "jo1")[(set: $inventoryofthinkers to it + (a: "Jenny Odell"))]

note: to test the above:

  1. Place the code in a Passage of a Harlowe 3.x based project.
  2. Use the Twine 2.x application’s Publish to File option to generate a Story Html file.
  3. Open that Story HTML file in your web-browser.
  4. Add the relevent query parameter to the end of the URL, and execute the it.
  5. Navigate to the Passage that contains the above code.

eg. if the Story HTML file you generate is named adventure.html, and the query argument looks something like i=a,b,jo1 then end of the URL in the web-browser’s location bar should look something like…

adventure.html?i=a,b,jo1
2 Likes

thank you so so much! this worked perfectly!!

1 Like