0 votes
asked 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
answered by (2.7k points)
selected by
Best answer

This is how:

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



commented by (560 points)
That's fantastic, thank you so much for your help! :)
commented by (131k 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>>


commented by (560 points)
Thanks a lot Greyelf, that's really helpful!
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.