Displaying different text based on the last passage seen

Twine Version: Twine 2
Story Format: Harlowe3.2.3

Hi, I am very new to Twine (and have already learned a lot by searching the posts here, so thank you all very much for that already!)

I am trying to write a set of passages where the user can perform different tests on a set of different items. So for example, I have the following code which shows the test result for one of the items ($C1, which is defined elsewhere).

(link: "Click to see the test result for unknown $C1")[Unknown $C1 is ''negative'']

I have six different unknown items ($C1-$C6) and it is a little tedious to have to create the same passage for each of them … is there a way to get the variable to update automatically based on the last passage viewed? (i.e., if the user had last viewed a page about item $C4, the link would automatically update.)

(The user can do these tests on unknowns ($C1-$C6) in any order, the numbers are just there to help me organise myself.)

I realise that this may not be possible, but thanks a million for any help!

You can use the (history:) macro to retrieve an Array containing the Names of all the previously visited Passages, in the order they were visited. And you can use the last data-name to retrieve the Name of the last Passage visited from that Array.

(history:)'s last

So you can use the above combined with the (if:) family of macros to conditionally do something.

(set: _lastPassage to (history:)'s last)
(if: _lastPassage is "AAAA")[ ...do something... ]
(else-if: _lastPassage is "BBBB")[ ...do something else... ]
(else-if: _lastPassage is "CCCC")[ ...do the other thing... ]

That is so incredibly brilliant, works beautifully! Thank you ever so much, you’ve saved me I-don’t-know-how-many hours of tedious copy/pasting!