I believe ozubon's first solution (or a variation of it) is what you're after, but can you answer a few more questions to be sure?
You say you're using a free text plugin, so the variable can contain a whole phrase. Which variable - the one entered by the user? In that case, do you want to know if the user entered a particular (whole) word as part of that phrase? Or do you want to compare the whole input from the user with a list of phrases?
If the user enters "I have a headache" and you are looking for the word head, you would want it to return false?
But if they entered "My head is aching" and you're looking for the word head, you would want it to return true?
In that case, the variable contains the string you're searching in, and you will hardcode the string you're searching for:
Code:
RegExp(" " + $gameVariables.value(x).toLowerCase() + " ").test(" head ");
The above will convert the user's input to lower case and add a space at either end, then search for the word head with spaces around it. So it will match Head at the start or end of the phrase, as well as in the middle, as long as it's not a part of a longer word.
There are other ways to do it, like convert the input text to an array using spaces as delimiters, then comparing each element to the word you're after.
I will try to give a more practical example.
Since variable (x) can contain a whole sentence, it can be useful for me to make the PC distinguish in affirmative / interrogative / negative sentences.
If it can be said that an interrogative sentence can be verified on the basis of the presence of a "?", and an affirmative sentence can be anything that is neither classified as a question nor a negative, the problem comes precisely in identifying a negative phrase.
In my language you can use "no" or "non" to deny, but these are too frequent particles.
I may have to say "nonno" (=grandfather) in an affirmative phrase, but that word contains both "no" and "non"... And a lot of words here can end with a "-no", even verbs.
Now... I, in fact, have tried to use " no " and, in some circumstances, it worked, but what if my phrase just begins with "No, blabla"? " no " will turn false (cuz there is no space at the beginning), and "no " will still turn true for all words ending with "-no".
So the best thing would be something that can check fot the presence of ONLY "no" in the string. Without anything before or after.
I tried also $gameVariables.value(x)===("no") but it is very restrictive, since the whole sentence must be = "no".
I don't mean you search for " the " instead of "the" using includes(), although it's possible to write similarily simple code that finds the word "the" in a string without finding it in "these", "they", or "thesaurus". Interpunctation is not a problem either because that's a very limited group of characters to make rules for, especially in english. You most likely do not need a complex processing of sentences unless you're trying to achieve something very specific. Needing to pick out certain words from a string, for the purpose of a game isn't as complicated as you're making it seem.
This seems exactly what I was searching for, but I have no idea the level of complexity it requires.
Do you have any idea?