Twine Behavior Reference

These are generally for Harlowe 3.x. Javascript can also be used.

Delay Passage Appearance

The following JavaScript code can be used in a scenario where you want, a, the entire passage to fade-in, then the span “bright” to fade in, then the passage “really” to fade in. In this case span “really” is embedded in span “bright”, hence the difference despite both being hidden for 5000. Note. this must be wrapped in tags:

$('tw-passage').hide().fadeIn(3000);$('span.bright').hide().fadeIn(5000);$('span.really').hide().fadeIn(5000)

Harlowe: If/If

And example of testing to see if aggro is greater than 1, then load the first, then if aggro is also greater than 3, add the results of lots of being hit on the head with cooking pots:

(if: $aggro > 1)[Several other mothers appear behind her, each with her own kitchen implement.] (if: $aggro > 3)[(transition: "shudder")+(transition-time: 10s)[They swim in and out of focus...]]

Note: Rather than using == or = as the operand for testing if a value is equal to something, you have to use the word “is.” e.g. (if: $dinner_count is 4)[do thing]

Harlowe: Set & Update Variables

This sets the initial $aggro variable to false. Now it can be tested (because this particular game happens to involve loops and always needs to be able to test, if you return to an earlier scene after setting aggro to a number in a later scene. $aggro can be ‘false’ as well as a number (and other things). The following is the very opening line:

(set: $aggro to false)Everything is dark...

Later on, we test whether $aggro is still false or we’ve already been through the loop. If it’s fallse, we set it to 1. If it’s already a number, then it’s no longer false, which it was in the beginning (note, if we hadn’t set it there, this would cause an error). Else, in this case, returns true of $aggro >= 1. This “it + 1” is an incrementation. By wrapping that set with [ ], we add in a span class which fades in to call the user a “dumbass” because they keep repeating the loop.

(if: $aggro is false)[(set: $aggro to 1)](else:)[(set: $aggro to it + 1) <span class="dumbass">Dumbass.</span>]

Harlowe: Live and Go-To

Based on variables, we determine what the next scene should be. However, rather than simply display a link, we want to send the user there.

go-to sends the user to a scene. [(go-to: "Wake up")] will send the user to the scene “Wake-Up.” However, we want the user to have a few seconds on this page. Perhaps it’s because we want them to read a thing first. Perhaps there’s another reason.

live means that the thing doesn’t go live for X number of seconds (or milliseconds with ms, etc.). [(live: 4s)[(go-to: "Dumbass")]] will send a user to the scene “Dumbass,” but only after 4 seconds on this page.

Below is an example of some rather complex logic. Note, the set and update test occurs directly above this, therefore $aggro can no longer be false. It must be either 1 or another integer.

(if: $aggro < 5)[(live: 4s)[(go-to: "Wake up")]](else:)[(live: 4s)[(go-to: "Dumbass")]]

Harlowe: Shuffle Array

Rather than separately declare an array and shuffle it “shuffled:” allows you to write out an array which will always be shuffled before it loads, rather than appear in the order you write it. The following sets the variable $tall to a shuffled array of scene lists (strings must be in “”). Each time a person loads the game, the scene lists will be in a different order. However each will only occur once if you iterate through the array (see next).

(set: $tall to (shuffled: "Reach High Places","Fix the Roof","Retrieve Snacks","Play Two-Headed Giant","Climb Trees"))

Harlow: Iterate Through Array

Whether a shuffled array or a normal array you can access an item in an array by referencing its position. Note: this uses a 1-index vs. a 0-index. It can be accessed as 1st, 2nd, 3rd of $array but that’s terrible for iteration. You can also wrap an integer in parentheses. (4) of $tall would get you the fourth item in the array tall (which may or may not have been shuffled, depending on how it was created, see above. You can use variables to set the integer.

The code below is from a passage which exists entirely to move you through scenes in order in the array. It functions to increment an integer value and then immediately send you to the corresponding scene in the array. If this is all the code their is, players will never see it:

(set: $tall_count to it + 1)(go-to: ($tall_count) of $tall)

Further explanation: In this sequence, you may have started with $tall_count at 0 as set in a previous passage or it may already be 1+. When you click through to this passage, it makes sure that the $tall_count integer is at least 1 (again, because we’re working from a 1-index) or is the next integer in the sequence. It then uses the “go-to” command to automatically load a new scene with using the integer to get the scene name from the array. The array might be:

(shuffled: "Reach High Places","Fix the Roof","Retrieve Snacks","Play Two-Headed Giant","Climb Trees")