How to Know Whether to Use "A" or "An" for an Unknown Variable


#1

So in my current project, the sentence that I am trying to write is:
"No way! You’re a $!{lastname}!"
But that would create an issue if their last name started with a vowel.
"No way! You’re a Eaton!"
See what I mean?
So how would I create a potential *if statement for the first letter of the word?
Any help would be greatly appreciated, thanks! :smile:


#2

Well, I think there’re 3 steps you need to do.

  1. Establish a boolean variable to identify the first letter of the lastname. This variable will contain TRUE for a vowel, and False for consonant (or vice versa, your call)
  2. On your character generation page, put a conditional check code to identify the first letter.
    Use *if (surname#1 = "A") or (surname#1 = "E") and so on.
    Refer to the “Extracting letter” section of the wiki.
  3. Using multireplace @{}, you can now issue a or an depending on the variable you just set up.

For example, let’s say ur variable is [a] and the PC has their lastname as “Eaton.”

You can do

This should produce a natural sounding texts despite the PC’s lastname.


It might looks intimidating at first, but when you get the hang of it, it’s actually a piece of cake.
In fact, my story is filled with those @s :laughing:


#3

If it’s an issue with a lot of your variables, or a variable set by the player, then you could set a special variable for a/an like Szaal suggests.

In my own game, I’m pretty sure there’s only one variable where this is an issue – moot, which can be set as “moot” or “apella”. So I just made a second variable, a_moot, which is set to either “a moot” or “an apella,” and I use it wherever the sentence structure demands an indefinite article. Way easier.

This wouldn’t work for an input_text variable where you’ve no control over whether the player has started it with a vowel. I’ve got a few of those, and I just don’t use them in ways that demand the use of a/an. In your case, that would mean switching to a different sentence structure e.g. “No way! You’re one of the ${lastname}s!”

Which works best for you will probably depend on how many situations you think there’ll be where you’ll want a a/an variable. I tried a similar avoidance approach with “his/hers” – just not use it and restructure in a way that always used “his/her” – but eventually recognized that I was circumventing it enough that I might as well just make the variable.


#4

You’re right, I never thought about it :thinking:

Hmm… in fact, I just realized another coding method which is less complicated than my previous comment… but let’s see which one the OP’s prefer :sweat_smile:


#5

Thank you Havenstone and Szaal (Not entirely sure how to tag you guys). I think that for this particular case, I will just change the sentence structure, because I do not think that a similar case will happen later in my story, but if I do change my mind, I will definitely use your input. Thank you very much!