Hi everyone,
I'm working in Harlowe Twine 2.0.
I am creating an in-game vocabulary assessment that tests players as they progress through the game. I have an array $questCompleted1 which includes a list of datamap variables $vocab1, $vocab2, $vocab3. I am using the array $vocabAssessment to add arrays from completed quests to another array so that I can randomly select a vocab variable to test the players based on completed quests. Now I would like that as players complete additional quests I could add an array from other quests to the array $vocabAssessment. So something like, the following: (set: $vocabAssessment to it + $completedQuest2) where $completedQuest2 is equal to ($vocab3, $vocab4, $vocab5). The issue is that now $vocabAssessment contains $vocab1, $vocab2, $vocab3, $vocab3, $vocab4, $vocab5)... $vocab3 is produced twice. Is there a way to remove duplicates in an array?
Comments
Here is all the code:
If you run that you'll see there is no duplication of the contents of $vocab3, and trying to print $vocabAssessment's 6th value throws an error.
The challenge with this method is its scalability. If you have dozens of quests, and each quest can add up to dozens of $vocab datamaps, you have a lot of writing ahead of you.
Important note: Make sure you set $vocabAssessment to it + an array, because setting $vocabAssessment to it + a datamap causes errors due to $vocabAssessment being an array and being unable to merge with a datamap. Putting the datamap in a single-element array fixes this by making it so that you're just adding array elements to other array elements.
If the project is huge, I'd consider SugarCube to make use of loops and whatnot.