0 votes
by (120 points)
Hey all!

Twine 2 - Harlowe


I'm relativity (very) new to this whole thing and i'm really just goofing around trying to learn it. Anyway, I'm trying to keep a list of descriptive words for the PC. Using hair length as an example, i want it to change over time, from short to medium, then maybe back again. I assumed i would use a variable to keep track of what "stage" it was at, then use that to call from the list. Not sure if i'm getting close or not, and even then i'm having little success. Ideas?


Sorry if that made little sense.

1 Answer

0 votes
by (159k points)

note: You state you are using Harlowe but not which version, I will assume you are using v2.1.0 because it's the default story format of the latest release of Twine 2.

You are correct in your break down of the issue. You basically need two things:

1. Some way to track the current style, and you can use a Story variable (eg. $hairStyle) to do that.

2. Some way to store the style descriptions.

You could also use a Story variable to do that, however the descriptions generally wont change for the lifetime of a play-though (we call this Static or Constant data) and storing that sort of data within a Story variable is wasteful.(*)
A better place to store that sort of data is within the JavaScript environment of the web-browser.

The following JavaScript code should be placed within the Story Javascript area of your project, it creates a Namespace named GE with a property named hairStyles to contain the style descriptions.

Create a Namespace to contain your JavaScript code properties and functions, so that they don't interfer with those of the web-browser itself.

Ideally it should have a name that is unique and meaningful to your story, I will use one named GE (my initials).
window.GE = window.GE || {};

/* Define an Array property to store the different hair styles descriptions. */
GE.hairStyles = ["short", "medium", "long"];

The following TwineScript demonstrates how to use a story variable named $hairStyle to access one of the descriptions in the GE.hairStyles property. The first element of an JavaScript Array has an index of 0 (zero), the second is 1 (one) as so forth.

(set: $hairStyle to 0)\
Current style: (print: GE.hairStyles[$hairStyle])

(set: $hairStyle to 1)\
Current style: (print: GE.hairStyles[$hairStyle])

(set: $hairStyle to 2)\
Current style: (print: GE.hairStyles[$hairStyle])

(*) It's wasteful because the story format's History & Save systems needs to store the data, which unnecessarily makes each of those systems take up more memory and more storage space within the web-browser's Local Storage cache. Moving the storage of that data to JavaScript reduces the memory usage and removes the need to use the Local Storage cache (for that data) entirely.