0 votes
by (560 points)
Sugarcube 2.18.0

Hi there,

I currently have a Q&A with a NPC using a textbox - if the player gets the correct answer, a video loads with the NPC answering the question. At the moment, the user can only enter one word - e.g. if they want to ask someone if they're thirsty, the only acceptable input is "thirsty".

Is there a way to set the answer so that if the user inputs "have you felt any more thirst recently" then the phrase "thirst" can be recognised from within the textbox and be marked as correct?

Thanks a lot

1 Answer

+1 vote
by (2.7k points)
selected by
 
Best answer

This is how:

<<textbox "$Answer" "">>
<<if $Answer.includes("thirst")>>Do something<</if>>

 

 

by (560 points)
That's fantastic, thank you so much for your help! :)
by (159k points)

You may want to handle the use-case of someone entering Thirst instead of thirst, or any other combination of upper & lower case letters.

If so then you should include the Java-script toLowerCase() function in SmuJamesB's solution, something like the following.

<<textbox "$Answer" "">>
<<if $Answer.toLowerCase().includes("thirst")>>Do something<</if>>

 

by (560 points)
Thanks a lot Greyelf, that's really helpful!
...