Any hints about how I'd tackle this in Twine Harlowe?
E.g. I'd want a positive result if the words were "eyes" and "smile" (both contain e and s), or a negative result if the words were "eyes" and "blink" (no letters in common).
Something to do with splitting a string into an array of substrings for starters, I guess
Thank you!
Comments
You could use a combination of Javascript's String split() method, the new Array some() method and an inline function to do what you want. It would look something like the following.
But there are two issues with the above:
1. The Array some() method may not exist in older web-browsers, which you can solve by adding the following Polyfill from MDN to the start of your Story Javascript area.
2. Harlowe has problems parsing the expression and throws a "Unexpected token" error for the following.
You can get around this issue by creating a custom method and using that instead. There are two ways you can do this:
a. Create a Custom Namespace to contain your new method.
Add the following to your Story Javascript area, it creates a new My namespace and assigns a new containsCharacters method to that namespace. This code needs to appear later in the passage than the Array some() method Polyfill. ... to use the new method add the following to a passage, it creates three variables and then checks if the characters in two of them are contained within the third.
b. Extend the built-in Javascript String prototype.
warning: This technique is consider bad by some (many?) because it can interfere with current (or future) Standard methods added by web-browser developers.
Add the following to your Story Javascript area, it extends the built-in Sting prototype to include a new containsCharacters method. This code needs to appear later in the passage than the Array some() method Polyfill. ... to use the new method add the following to a passage, it creates three variables and then checks if the characters in two of them are contained within the third.