Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to require a specific answer to continue game

Hiya! I'm (obviously) new, both to Twine and... well, everything that comes with it!

So I apologize if this question is stupid...

I want to give the player a passage with a scrambled sentence, and they have to solve it and enter the correct version of it so they can continue onto the next passage.

Maybe (meaning probably) it's just my extreme noobishness, but yeah, how would something like that be done? :\

Comments

  • Try something like this:
    (set: $password to (prompt: "What is the password? Hint: The password is Hakuna Manata.") )

    (if: $password is "Hakuna Matata")[You are correct.](else:)[You are wrong. [[Try again->Enter the password]].]
    The only downside is that the player will have to enter the sentence exactly like you want. Exact same spaces, punctuations. Exact same words, with no typos.

    I'm attaching a story with a working example for you. Just unzip it and import it into Twine 2 (after importing you'll have to refresh for it to appear in the story list)
  • Yeah, I don't see a string conversion keyword available.

    Feature Request: We need an uppercase and lowercase string conversion method.

    Otherwise passwords are going to be limited to numbers (which I guess is why Porpentine used a numeric passcode in Ultra Business Tycoon III: http://aliendovecote.com/uploads/twine/tycoon/nfo.png ).
  • This also would be handy when using (either: $Var1,$var2) and/or conditions in the middle of dynamic sentences where any text pulled from an var or array that begins with an uppercase letter and you want to switch it to lowercase or the opposite if you want to begin a new sentence with it. It would be neat if we could go (PCase (print: $VarX)) or (LCase: (print: $VarX)) or something.
  • edited August 2015
    You can use elseif conditions to cover the most common variations of lack of caps.

    e.g.
    (if: $password is "Hakuna Matata")[You are correct.](elseif: $password is "hakuna matata")[You are correct.](elseif: $password is "Hakuna matata")[You are correct.](else:)[You are wrong. [[Try again->Enter the password]].]
    
  • Or just use a function like Javascript's toLowerCase() to force the user's input to a known case and check against that value, this way it does not matter which case the user entered.
    (set: $password to (prompt: "What is the password? Hint: The password is Hakuna Manata."))
    
    (set: $password to $password.toLowerCase())
    
    (if: $password is "hakuna manata")[You are correct.](else:)[You are wrong.]
    
  • Is there a way to check if a text area contains a word? So that if they type "the password is bacon" all that matters is bacon
  • You could use the Javascript indexOf function:
    (set: $password to (prompt: "What is the password? Hint: the password is bacon."))
    
    (set: $password to $password.toLowerCase())
    
    (if: $password.indexOf('bacon') > -1)[You are correct.](else:)[You are wrong.]
    
    ... or even the newer ES6 includes function, though this may not work on all browsers:
    (if: $password.includes('bacon'))[You are correct.](else:)[You are wrong.]
    

    WARNING:
    Both of the above functions are looking for a sequence of characters (not words), so if you are looking bacon then both of the following user inputs would also be valid because the both contain the letters bacon:
    a. the password is baconxxxxx
    b. the password is xxxbaconxxx
  • greyelf wrote: »
    You could use the Javascript indexOf function:
    (set: $password to (prompt: "What is the password? Hint: the password is bacon."))
    
    (set: $password to $password.toLowerCase())
    
    (if: $password.indexOf('bacon') > -1)[You are correct.](else:)[You are wrong.]
    
    ... or even the newer ES6 includes function, though this may not work on all browsers:
    (if: $password.includes('bacon'))[You are correct.](else:)[You are wrong.]
    

    WARNING:
    Both of the above functions are looking for a sequence of characters (not words), so if you are looking bacon then both of the following user inputs would also be valid because the both contain the letters bacon:
    a. the password is baconxxxxx
    b. the password is xxxbaconxxx

    Sounds good, thank you!
  • Sorry, how do I do that in sugarcube? The .indexof part doesn't seem to be working. Sorry if it's a stupid question, the javascript stuff is all new to me.
  • The SugarCube syntax is almost the same as Harlowe's:
    <<set $password to "the password is Bacon">>
    <<set $password to $password.toLowerCase()>>
    
    /% using indexOf function %/
    
    <<if $password.indexOf('bacon') > -1>>You are correct.<<else>>You are wrong.<</if>>
    
    
    /% or using the ES6 includes function %/
    
    <<if $password.includes('bacon')>>You are correct.<<else>>You are wrong.<</if>>
    
Sign In or Register to comment.