Twine 2: Set a Variable as Part of an Array?

Twine Version: 2.3.5
Story Format: Harlowe 3.1.0

So I have this array and I want to set a specific variable to the value of one of the items in this array. The array is a list of names (John, George, Mary, Todd, etc…) and the variable is $teammate. I want to be able to have the variable pick a specific spot from that list and set it to the name of that teammate. Here’s what I’ve tried so far:

(set: $teammate to $name[1])

I’ve also tried:

(set: $teammate to (print: $name[1]))

And I’ve tried rewriting either of the above, putting various things in quotes. So, like:

(set: $teammate to “$name[1]”)

or…

(set: $teammate to “(print: $name[1])”)

and even…

(set: $teammate to (print: “$name[1]”))

Nothing so far has worked, so either I’m overlooking something with these commands or I’m using the wrong things to do this.

Please help!

Harlowe does arrays kind of weird (IMO). I think it’s wordy to be friendly to new coders, but it actually makes things more difficult for those that are used to a certain standardization between languages, like you seem to be.

Anyway! What you’re looking for is this:

(set: $teammate to $name's 1st)

Here’s the reference: https://twinery.org/wiki/harlowe:array

1 Like

Ah, I see! I’m actually rather new to Twine (and to programming in general), but you’re right that Harlowe can be weird in places.

Thanks!