[HELP] Why Prompt answer not always working

Post all technical issues and questions here. We'll gladly help you wherever we can.
Post Reply
Epton
Explorer At Heart
Explorer At Heart
Posts: 116
Joined: Sun Mar 05, 2017 9:56 am

[HELP] Why Prompt answer not always working

Post by Epton »

Hey Guys, I'm using Prompt and give it a Variable 'Answer' then I use an IF with
Answer == Answer.trim().match(/^No Miss|No Ma'am|no|no Sir|No *goddess$/i)
But for some reason when I type 'no goddess' it doesn't work and if I type 'no' it does work :-/
Why it doesn't validate the 'goddess' after each string I've specified :\'-( :rant:
Thamrill
Explorer At Heart
Explorer At Heart
Posts: 301
Joined: Thu Jan 03, 2013 4:55 pm
Gender: Male
Sexual Orientation: Straight
I am a: Submissive

Re: [HELP] Why Prompt answer not always working

Post by Thamrill »

Epton wrote: Tue Aug 13, 2024 9:01 pm Hey Guys, I'm using Prompt and give it a Variable 'Answer' then I use an IF with
Answer == Answer.trim().match(/^No Miss|No Ma'am|no|no Sir|No *goddess$/i)
But for some reason when I type 'no goddess' it doesn't work and if I type 'no' it does work :-/
Why it doesn't validate the 'goddess' after each string I've specified :\'-( :rant:
Tried it out in javascript tester, I think the issue is that if you put "No goddess" (and the same is true for "No Sir"), it matches the simple "no" options, which then fails the comparison check; try putting the "no" option last, should work
Image

Image

Image
Epton
Explorer At Heart
Explorer At Heart
Posts: 116
Joined: Sun Mar 05, 2017 9:56 am

Re: [HELP] Why Prompt answer not always working

Post by Epton »

Thamrill wrote: Wed Aug 14, 2024 7:32 am
Epton wrote: Tue Aug 13, 2024 9:01 pm Hey Guys, I'm using Prompt and give it a Variable 'Answer' then I use an IF with
Answer == Answer.trim().match(/^No Miss|No Ma'am|no|no Sir|No *goddess$/i)
But for some reason when I type 'no goddess' it doesn't work and if I type 'no' it does work :-/
Why it doesn't validate the 'goddess' after each string I've specified :\'-( :rant:
Tried it out in javascript tester, I think the issue is that if you put "No goddess" (and the same is true for "No Sir"), it matches the simple "no" options, which then fails the comparison check; try putting the "no" option last, should work
Maybe it was cuz of the 2 no, but I deleted the middle one and it weirdly worked, but I noticed something very wrong with what I had written so I changed it lol. Thanks for the answer, it clarified my mind.
kerkersklave
Explorer At Heart
Explorer At Heart
Posts: 709
Joined: Sun Jul 06, 2014 2:11 pm
Gender: Male
Sexual Orientation: Open to new ideas!
I am a: Slave

Re: [HELP] Why Prompt answer not always working

Post by kerkersklave »

Do you really put this as a condition?

Code: Select all

Answer == Answer.trim().match(/^No Miss|No Ma'am|no|no Sir|No *goddess$/i)
You are comparing "Answer" to the result of triming and matching. match returns null if there is no match, so it should be:

Code: Select all

null != Answer.trim().match(/^No Miss|No Ma'am|no|no Sir|No *goddess$/i)
The reason you get true for "no" is, that | has priority over ^ and $, so your expression matches something that starts with "No Miss", contains "No Ma'am", "no" or "no Sir" or ends with "No goddess". If you then compare Answer to that match result it will convert the match result for whatever has been matched.

For "no" that works, even for "No" it wont work. "No" is also matched for "No Goddess" because Javascript takes the first match, which is "no" as you are not requiring it to match to the end.

What you actually want is this:

Code: Select all

null != Answer.trim().match(/^no( +(Miss|Ma'am|Sir|goddess))?$/i)
And because javascript is actually converting most values to true and null and some others to false, you could directly use:

Code: Select all

Answer.trim().match(/^no( +(Miss|Ma'am|Sir|*goddess))?$/i)
as a condition for if.

If you press f12 in Chrome or Firefox you will get a javascript console, where you can evaluate expressions and see what you get as a result.
Post Reply