Twine Version: 2.6.2
Harlowe 3.3.5
Hi all,
I am having some problems with understanding how arrays work and implementing them in my story, I am hoping that you can help?
I have set up an array to track the information that a player learns in my story, and I would like to be able to check whether a particular piece of information is present in that array. (& then to modify the next steps accordingly - i.e., if they haven’t learned X, the story will prompt them to go to the correct passage to learn X)
Somehow the structure and commands for working with arrays just don’t make sense in my brain no matter how many times I read the documentation, so apologies if this is a really stupid question.
This is basically the sort of thing I am trying to set up, copied below (though the strings in the array in practice would be picked up in different passages - but I’ve put it all in one to test it).
(set: $test to (a: "Gram stain is positive", "Malachite green is negative", "catalase is positive"))
(set: $test to it + (a: "lactose fermentation is positive"))
(if: $test contains "lactose")[Yay!]
(else:)[Nope]
(if: $test contains "lactose fermentation is positive")[Hello!]
(else:)[Woe!]
When I try running this code, it prints “Nope” and “Hello!” - it seems to only work if I am matching an entire string in an array.
Is this correct? Is there a way (that isn’t too complicated) to look for a partial string in an array? (I would like to be able to search for whether they’ve done the test, regardless of the result - which is why I don’t want to just type out the entire string… I was hoping that the first if statement above would have printed “Yay!”)
[I can’t do this by checking whether the passage with the test is in the player’s history, because of the way that I’ve set the story up. Each test page has different options that are conditionally revealed depending on the player’s choices + some amount of randomisation, it wouldn’t be feasible to set up a passage for each of the different test results.]
Thanks very much for any help that you can give!!