Error: This lambda has two variables named

I am using Twine 2.3.3 with Harlowe 3.0.2. I want to have headlines in a given order. I also want to track which headlines the reader has visited.

An array provides order, and a datamap can track by storing true or false for each element. So I intialized an array with the headlines. Then I looped over the array to add each element to a datamap with false as value.

(set: $fragment_titles to (array: "a b c", "d e f", "g h i"))
(set: $fragment_completions to (dm:))
(for: each _frag_title, ...$fragment_titles)[(set: $fragment_completions's _frag_title to false)]
(print: $fragment_completions)

As a result the following error message appears:

This lambda has two variables named 'frag_title'.

Apparently the datamap has only one element, with the name of the temporary variable as key because the following is the output of the last print statement:

_frag_title false

Please help. What do I need to do differently?

The underscore character is used to indicate a temporary variable. The fact that you are using the same character to separate the individual ‘words’ that make up your multiple ‘word’ variable names is confusing the Harlowe TwineScript parser.

If you change the name of your _frag_title temporary variable to something like _title then your code will no longer result in that error. Also as noted within the Array documentation, you are meant to use parenthesis when using an expression to indicate a collection element’s index/key.

(set: $fragment_titles to (array: "a b c", "d e f", "g h i"))
(set: $fragment_completions to (dm:))
(for: each _title, ...$fragment_titles)[(set: $fragment_completions's (_title) to false)]
(print: $fragment_completions)
1 Like