Attempts to prepend the correct indefinite article (e.g., 'a' or 'an') based on the indicated word or phrase. Many times over more complicated than simply checking if the first letter is a vowel, this macro will correctly assign fairly complicated cases, like "a UFO", "an X", "an hour", "a European", and "a horror", among others. For edge cases, users can also set up overrides to force the system to identify certain words or phrases as requiring one article or the other.
THE CODE: Minified. Pretty.
DEMO: Available.
GUIDE: Not available.
Syntax:
<<a text>>
<<an text>>
<<A text>>
<<An text>>
This macro attempts to take the following text and prepend it with the appropriate indefinite article. If the macro name is capitalized, e.g. <<A>>
or <<An>>
the indefinite article that is generated will be capitalized in the output. There is functionally no difference between <<a>>
and <<an>>
and between <<A>>
and <<An>>
, they are included simply to feel better to write based on what you're writing.
Tip
The parser used by this macro contains a lengthy list of common special cases and a series of pretty intricate rules for how it determines whether to use 'a' or 'an', there will be exceptions and strange cases it can't account for. For those cases, you will want to use overrides
Argument:
text
a string of text, can be a word or a bunch or words.
Examples:
<<set _adjective to either('steel', 'adamantium', 'stone', 'iron', 'bronze', 'iridium');
You found <<a _adjective>> sword!
<<An _adjective>> sword fell off the cart.
Syntax: <<setarticle article text [caseSensitive]>>
This macro adds an override to the <<a>>
-style macros, allowing you to assign certain words or phrases to use a specific article every time. You can optionally make the override case-sensitive, so that only phrases that match the exact case of the provided text are overridden.
[!DANGER] This macro will only work in your
StoryInit
special passage. Overrides must be set up before the story begins. Failure to call this macro in theStoryInit
special passage or earlier will throw an error.
Arguments:
article
the string'a'
or the string'an'
—the article to set the provided text to use.text
a string of text, can be a word or a bunch or words, to assign an article.caseSensitive
if a third argument is provided and truth-y, the text will only be overridden if it matches the exact case of the override.
Examples:
/* add the word 'US' (case-sensitive) and assign it the article 'a' */
<<setarticle 'a' 'US' true>>
<<a 'US'>> citizen /* -> 'a US citizen' */
<<a 'un'>>-vs-them situation /* -> 'an us-vs-them situation' */
<<setarticle 'a' 'onceler'>>
<<an 'Oncler'>> /* a Onceler */
Syntax: setup.articles.find(text)
This function takes a string and finds the correct indefinite article and returns it.
Returns: a string
Arguments:
text
(string) a string of text, can be a word or a bunch or words.
Examples:
setup.articles.find('UFO'); // 'a'
setup.articles.find('animal'); // 'an'
setup.articles.find('1'); // 'a'
setup.articles.find('86'); // 'an'
setup.articles.find('honorable man'); // 'an'
setup.articles.find('heir to the king'); // 'an'
setup.articles.find('horrible day'); // 'a'
setup.articles.find('painting'); // 'a'
Syntax: setup.articles.output(text)
This function takes a string and finds the correct indefinite article, then appends it to the source string and returns the whole thing.
Returns: a string
Arguments:
text
(string) a string of text, can be a word or a bunch or words.
Examples:
setup.articles.find('UFO'); // 'a UFO'
setup.articles.find('animal'); // 'an animal'
setup.articles.find('1'); // 'a 1'
setup.articles.find('86'); // 'an 86'
setup.articles.find('honorable man'); // 'an honorable man'
setup.articles.find('heir to the king'); // 'an heir to the king'
setup.articles.find('horrible day'); // 'a horrible day'
setup.articles.find('painting'); // 'a painting'
Syntax: setup.articles.override(article, text, caseSensitive)
This function creates an override the same way the <<setarticle>>
macro does.
[!DANGER] This function will only work in your
StoryInit
special passage or in you story JavaScript area. Overrides must be set up before the story begins. Failure to call this function in theStoryInit
special passage or earlier will throw an error.
Returns: nothing
Arguments:
article
(string) the string'a'
or the string'an'
—the article to set the provided text to use.text
(string) a string of text, can be a word or a bunch or words, to assign an article.caseSensitive
(boolean) if a third argument is provided and truthy, the text will only be overridden if it matches the exact case of the override.
Examples:
setup.articles.override('a', 'US', true);
setup.articles.override('a', 'onceler');