+1 vote
by (170 points)
I was playing with Twine 2. Made a small little story in Harlow.

I read that Sugarcube 2 is much more flexible and I wanted to just start with Sugarcube instead of Harlow.

I want to make a series of passages that basically give a puzzle and clues, and then have that person answer in a textbox. If they get the answer right, then it would say "correct" with a link to the next passage. If they get it wrong, then it just says "incorrect" and they can continue to try and figure it out right there on that page.

 

I am not a coder or programmer at all. I am able to copy/paste and change some of the words around to fit my story. I've searched forums and sites and tutorials and Youtube and  most of the examples have been in Harlow. But even the Sugarcube 2 ones have not been exactly this scenario, and I simply don't understand the language enough to create it on my own.

 

I hope someone can help. Thanks in advance.

1 Answer

+2 votes
by (62.7k points)

Try something like this:

<<set $answer to ''>>\
<<textbox '$answer' '' autofocus>>
<span id='textbox-reply'></span>

<span id='textbox-submit'>\
    <<button 'Submit'>>
        <<set $answer to $answer.trim().toLowerCase().replace(/\s\s+/g, ' ')>>
        /% trim() removes leading and trailing whitespace, toLowerCase() convert to lower case, replace turns multiple spaces between words into single spaces.  you may want to omit some or all of these methods. %/
        <<if $answer is 'the answer'>>
            <<replace '#textbox-reply'>>\
                Correct!\
            <</replace>>
            <<replace '#textbox-submit'>>\
                [[Link to next passage]]\
            <</replace>>
            <<run $('#textbox-answer').attr('readonly', 'true');>>
            /% prevent the textbox from being edited any further %/
        <<else>>
            <<replace '#textbox-reply'>>\
                Incorrect.  Please try again.\
            <</replace>>
        <</if>>
    <</button>>\
</span>
        

 

by (170 points)
This is glorious. Thank you. It works perfectly.
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.
...