[Help] 2 IF 1 Prompt can't figure why it goes to Else option

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: 111
Joined: Sun Mar 05, 2017 9:56 am

[Help] 2 IF 1 Prompt can't figure why it goes to Else option

Post by Epton »

I use 2 IF's for 1 Prompt. and no matter what I answer whether it matches or not it still goes to the Else option of the first IF.
I've tried to change their order and also merge them by placing the first IF inside the empty Else of the second IF.

Image
https://ibb.co/sQXRhYb
User avatar
indyc
Explorer At Heart
Explorer At Heart
Posts: 431
Joined: Sun Mar 28, 2021 10:03 pm
Contact:

Re: [Help] 2 IF 1 Prompt can't figure why it goes to Else option

Post by indyc »

I would put money on the problem being in the if condition but for a non-coder like me, I can't really help find the issue.

That being said, I highly suggest instead of prompting the player to type something in to instead have choice boxes. It may be personal taste for me but I really don't like typing in teases when so many are case sensitive, or a minor misspelling messes you up. At best it makes you stop whatever you were doing and use both hands which ruins the pace for me and in my opinion doesn't "present" as well.

Yay for having a virginity variable, looks promising.
Thamrill
Explorer At Heart
Explorer At Heart
Posts: 265
Joined: Thu Jan 03, 2013 4:55 pm
Gender: Male
Sexual Orientation: Straight
I am a: Submissive

Re: [Help] 2 IF 1 Prompt can't figure why it goes to Else option

Post by Thamrill »

Epton wrote: Sat Mar 05, 2022 5:49 pm I use 2 IF's for 1 Prompt. and no matter what I answer whether it matches or not it still goes to the Else option of the first IF.
I've tried to change their order and also merge them by placing the first IF inside the empty Else of the second IF.

Image
https://ibb.co/sQXRhYb
Not an expert in JS, but isn't string comparison done with === ?
Also, I maybe wrong, but I think the condition is wrong. Use an eval action with a console log to verify the returned value
Image

Image

Image
User avatar
kinkyswan
Explorer
Explorer
Posts: 46
Joined: Sun Feb 08, 2009 2:08 am
Gender: Male
Sexual Orientation: Straight
I am a: Submissive

Re: [Help] 2 IF 1 Prompt can't figure why it goes to Else option

Post by kinkyswan »

Epton wrote: Sat Mar 05, 2022 5:49 pm I use 2 IF's for 1 Prompt. and no matter what I answer whether it matches or not it still goes to the Else option of the first IF.
I've tried to change their order and also merge them by placing the first IF inside the empty Else of the second IF.
I think the problem is the slashes. So instead of:

Code: Select all

Answer == Answer.trim().match(/"no|no it does not|no it doesn't"/)
It should be:

Code: Select all

Answer == Answer.trim().match("no|no it does not|no it doesn't")
or

Code: Select all

Answer == Answer.trim().match(/no|no it does not|no it doesn't/)
So use the slashes or the double quotation marks, but not both :-)
User avatar
kinkyswan
Explorer
Explorer
Posts: 46
Joined: Sun Feb 08, 2009 2:08 am
Gender: Male
Sexual Orientation: Straight
I am a: Submissive

Re: [Help] 2 IF 1 Prompt can't figure why it goes to Else option

Post by kinkyswan »

Thamrill wrote: Sun Mar 06, 2022 7:02 am Not an expert in JS, but isn't string comparison done with === ?
Also, I maybe wrong, but I think the condition is wrong. Use an eval action with a console log to verify the returned value
The == is correct in this case because the return type of the match method is an array, while Answer is a string.

Assuming the user had typed in "no" in response to the prompt, the match method would return ["no"]. === only evaluates to true if the types on both sides are same, while == converts the expressions so they are the same type. So:

Code: Select all

"no" == ["no"]     // true because ["no"] is first converted to "no"
"no" === ["no"]   // false
Post Reply

Who is online

Users browsing this forum: No registered users and 50 guests